FrogRiverOne_sol2

PHOTO EMBED

Tue Jun 21 2022 16:46:16 GMT+0000 (Coordinated Universal Time)

Saved by @jacobsfo

// 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
}
content_copyCOPY