Skip to content

Instantly share code, notes, and snippets.

@clarkdo
Created January 29, 2018 07:32
Show Gist options
  • Save clarkdo/4c07619a0b46894317569149e7573c2b to your computer and use it in GitHub Desktop.
Save clarkdo/4c07619a0b46894317569149e7573c2b to your computer and use it in GitHub Desktop.
class Solution {
public int solution(int X, int[] A) {
int second = -1;
int count = 0;
boolean[] counter = new boolean[X];
for (int i = 0; i < A.length; i++) {
int pos = A[i];
if (pos <= A.length && !counter[pos-1]) {
counter[pos-1] = true;
count++;
}
if (count == X) {
second = i;
break;
}
}
return second;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment