Apple and Orange Problem Solution (Hacker Rank)






Solution


    static void countApplesAndOranges(int s, int t, int a, int b, int[] apples, int[] oranges)
        {
            int start = s;
            int end = t;
            int appleLoc = a;
            int orangeLoc = b;
            int appleCount = 0;
            int orangeCount = 0;
            int i, locationfall = 0;
            for (i = 0; i <= apples.Length - 1; i++)
            {
                locationfall = apples[i] + appleLoc;
                if (locationfall >= start && locationfall <= end)
                {
                    appleCount++;
                }
            }
            for (i = 0; i <= oranges.Length - 1; i++)
            {
                locationfall = oranges[i] + orangeLoc;
                if (locationfall >= start && locationfall <= end)
                {
                    orangeCount++;
                }
            }
            Console.WriteLine(appleCount);
            Console.WriteLine(orangeCount);
            Console.ReadLine();

        }

Share:

1 comment:

Popular

Tags

Mobile

Recent Posts