FrogRiverOne Codility C# solution
Find the earliest time when a frog can jump to the other side of a river.
Solution:
public static int FrogRiverOne(int X, int[] A) { bool[] leavesInPosition = new bool[X + 1]; int occupiedPositions = 0; for (int i = 0; i < A.Length; i++) { int position = A[i]; if (position <= X && !leavesInPosition[position]) { leavesInPosition[position] = true; occupiedPositions++; } if (occupiedPositions == X) { return i; } } return -1; }
And Here goes the Result, Got 100%
Frog River One |
Very helpful articles! To get some help with your online business, reach us at Reliable Movers
ReplyDelete