Jumping on the Clouds: Revisited

  • + 0 comments

    This is my solution in C# 😉

        public static int jumpingOnClouds(int[] c, int k)
        {
            int index = 0;
            int points = 100;
            bool isExit = false;
    
            while (true)
            {
                index += k;
                if (index > c.Length - 1)
                {
                    index = index % c.Length;
                    isExit = true;
                }
                int value = c[index];
    
                if (value == 1)
                    points -= 2;
    
                points--;
                if (index == 0 && isExit) break;
            }
            return points;
        }