Created
January 8, 2018 18:44
-
-
Save matheushf/d1237d8d78865b328d63a96f6c632c36 to your computer and use it in GitHub Desktop.
Javascript solution for the Codility Frog River One
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function solution(X, A) { | |
// write your code in JavaScript (Node.js 6.4.0) | |
let sequence = [0]; | |
let position = -1; | |
let counter = 0; | |
if (X === 1 && A[0] === 1) | |
return 0; | |
for (let i = 0; i <= A.length - 1; i++) { | |
if (A[i] <= X) { | |
if (!sequence[A[i]]) { | |
counter++; | |
} | |
sequence[A[i]] = A[i]; | |
if (counter === X) { | |
position = i; | |
break; | |
} | |
} | |
} | |
return position; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
function solution(X, A) {
}
I got 9% : )))) such poor score.