Skip to content

Instantly share code, notes, and snippets.

@piusayowale
Created August 16, 2022 18:04
Show Gist options
  • Select an option

  • Save piusayowale/e48fbdcd87b308f723702efbeb01e061 to your computer and use it in GitHub Desktop.

Select an option

Save piusayowale/e48fbdcd87b308f723702efbeb01e061 to your computer and use it in GitHub Desktop.
grid sorting greedy approach
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