Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Given a square grid of characters in the range ascii [ a - z ] , rearrange elements of each row alphabetically, ascending. Determine if

Given a square grid of characters in the range ascii[a-z], rearrange elements of each row alphabetically, ascending. Determine if the columns are also in ascending alphabetical order, top to bottom. Return YES if they are or NO if they are not.
Example
grid=['abc', 'ade', 'efg']
The grid is illustrated below.
a b c
a d e
e f g
The rows are already in alphabetical order. The columns a a e, b d f and c e g are also in alphabetical order, so the answer would be YES. Only elements within the same row can be rearranged. They cannot be moved to a different row.
Function Description
Complete the gridChallenge function in the editor below.
gridChallenge has the following parameter(s):
string grid[n]: an array of strings
Returns
string: either YES or NO
Input Format
The first line contains , the number of testcases.
Each of the next sets of lines are described as follows:
- The first line contains , the number of rows and columns in the grid.
- The next lines contains a string of length
Constraints
1<=t<=100
1<=n<=100
Each string consists of lowercase letters in the range ascii[a-z]
Output Format
For each test case, on a separate line print YES if it is possible to rearrange the grid alphabetically ascending in both its rows and columns, or NO otherwise.
Sample Input
STDIN Function
-------------
1 t =1
5 n =5
ebacd grid =['ebacd', 'fghij', 'olmkn', 'trpqs', 'xywuv']
fghij
olmkn
trpqs
xywuv
Sample Output
YES

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Data And Databases

Authors: Jeff Mapua

1st Edition

1978502257, 978-1978502253

More Books

Students also viewed these Databases questions