// you can use includes, for example:
// #include <algorithm>
// you can write to stdout for debugging purposes, e.g.
// cout << "this is a debug message" << endl;
int solution(int X, vector<int> &A) {
// write your code in C++14 (g++ 6.2.0)
vector<int>B(X,0);
//loop thru the array A
int sum = 0;
for(int i = 0; i <= A.size(); i++)
{
//ignore values not in range 1 to x, and if position is -1, insert time from a->position is filled
if(A[i]<=X && B[A[i]-1]==0)
{ sum++;
B[A[i]-1]=1;
}
if(sum == X){return i;}
}
return -1;
//loop thru the array B
}
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter