forked from Mohammed-Shoaib/Coding-Problems
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathE0087.cpp
More file actions
34 lines (30 loc) · 657 Bytes
/
Copy pathE0087.cpp
File metadata and controls
34 lines (30 loc) · 657 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
/*
Problem Statement: https://www.hackerrank.com/challenges/grid-challenge/problem
*/
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
string gridChallenge(vector<string> grid) {
for (int i = 0; i < grid.size(); i++)
sort(grid[i].begin(), grid[i].end());
for (int i = 0; i < grid.size(); i++)
for (int j = 1; j < grid.size(); j++)
if (grid[j - 1][i] > grid[j][i])
return "NO";
return "YES";
}
int main() {
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
vector<string> grid(n);
for (int i = 0; i < n; i++)
cin >> grid[i];
cout << gridChallenge(grid) << endl;
}
return 0;
}