The blog has moved to the new site F10Debug.com

Sunday, May 29, 2016

FrogRiverOne Codility C# solution

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

1 comment:

  1. Very helpful articles! To get some help with your online business, reach us at Reliable Movers

    ReplyDelete