Codility FrogRiverOne C# solution

By | November 7, 2017

Codility FrogRiverOne 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%

Codility FrogRiverOne Solution

                                                        Codility FrogRiverOne Solution

Leave a Reply

Your e-mail address will not be published. Required fields are marked *