// 45% FrogRiverOne
// Find the earliest time when a frog can jump to the other side of a river.
var X = 4;
var A = [1, 3, 1, 4, 2, 3, 5, 4];
function solution(X, A) {
// you can use console.log for debugging purposes, i.e.
// console.log('this is debug message');
// write your code in JavaScript (ECMA-262, 5th edition)
var A2 = [];
var Xarr = function (X) {
var tempArr = [];
for (var i = 1; i <= X; i += 1) {
tempArr.push(i);
}
return tempArr;
};
function uniquesSort(arr) {
var a = [];
for (var i = 0, l = arr.length; i < l; i++)
if (a.indexOf(arr[i]) === -1 && arr[i] !== '') a.push(arr[i]);
return a.sort(function (a, b) {
return a - b;
});
}
for (var i in A) {
A2.push(A[i]);
if ((uniquesSort(A2).toString()) === (Xarr(X)).toString()) {
return +i;
} else if (i >= (A.length - 1)) {
return -1;
}
}
}
console.log(solution(X, A));
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.