Created
August 16, 2022 18:04
-
-
Save piusayowale/e48fbdcd87b308f723702efbeb01e061 to your computer and use it in GitHub Desktop.
grid sorting greedy approach
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| string gridChallenge(vector<string> grid) { | |
| size_t jj, n = grid.size(); | |
| bool is_not = false; | |
| for (int i = n-1; i >= 0; i--) { | |
| string& r = grid[i]; | |
| sort(begin(r),end(r)); | |
| if (i == n-1) continue; | |
| string& p = grid[i+1]; | |
| for (int j = 0; j < n; j++) { | |
| if (int(r[j]) > int(p[j])) { | |
| is_not = true; break; | |
| } | |
| } | |
| if (is_not) break; | |
| } | |
| return (is_not?"NO":"YES"); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment