Skip to content

Instantly share code, notes, and snippets.

@clarkdo
Created January 26, 2018 05:23
Show Gist options
  • Save clarkdo/da4e020353a9e5f99456a74aba884079 to your computer and use it in GitHub Desktop.
Save clarkdo/da4e020353a9e5f99456a74aba884079 to your computer and use it in GitHub Desktop.
class Solution {
public int[] solution(int N, int[] A) {
int[] result = new int[N];
int currentMax = 0;
int max = 0;
for (int i: A) {
if (i == N + 1) {
max = currentMax;
} else {
int digit = result[i-1];
result[i-1] = digit = max > digit ? max + 1 : digit + 1 ;
if (currentMax < digit) {
currentMax = digit;
}
}
}
for(int i = 0; i < result.length; i++) {
if(result[i] < max) {
result[i] = max;
}
}
return result;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment