Sort by

recency

|

3009 Discussions

|

  • + 0 comments

    JS easy solution:-

    function countApplesAndOranges(s, t, a, b, apples, oranges) {
        const fallingFrutes = (startPoint, frutes) => {
            return frutes.reduce((acc, frute) => {
            const position = startPoint + frute;
            if (position >= s & position <= t) acc++;
            return acc;
            }, 0)
        }
        const appleFallsOnHouse = fallingFrutes(a, apples)
        console.log(appleFallsOnHouse);
        const orangesFallsOnHouse = fallingFrutes(b,oranges)
        console.log(orangesFallsOnHouse);
    }
    
  • + 0 comments

    Javascript solution:-

    function countApplesAndOranges(s, t, a, b, apples, oranges) {
        const isFallingOnHouse = (startPoint) => ((prev, frute) => {
            const position = startPoint + frute;
            if (position >= s & position <= t) prev++;
            return prev;
        })
        const appleFallsOnHouse = apples.reduce(isFallingOnHouse(a), 0)
        console.log(appleFallsOnHouse);
        const orangesFallsOnHouse = oranges.reduce(isFallingOnHouse(b), 0)
        console.log(orangesFallsOnHouse);
    }
    
  • + 1 comment

    `def countApplesAndOranges(s, t, a, b, apples, oranges): # Write your code here count1 = 0 count2 = 0 for apple in apples: if a + apple >= s and a + apple <= t: count1 += 1 print(count1) for orange in oranges: if a + orange >= s and a + orange <=t: count2 +=1 print(count2)

  • + 0 comments
    def countApplesAndOranges(s, t, a, b, apples, oranges):
        print(len([fruit for fruit in apples if fruit + a in range(s, t + 1)]))
        print(len([fruit for fruit in oranges if fruit + b in range(s, t + 1)]))
    
  • + 0 comments

    java, please critque if necessary -

    public static void countApplesAndOranges(int s, int t, int a, int b, List<Integer> apples, List<Integer> oranges) {
        int appleCount = 0;
        int orangeCount = 0;
    
        for(int i = 0; i < apples.size(); i++){
            if(apples.get(i) + a >= s && apples.get(i) + a <= t) {
                appleCount++;
            }
        }
    
        for(int i = 0; i < oranges.size(); i++){
            if(oranges.get(i) + b >= s && oranges.get(i) + b <= t) {
                orangeCount++;
            }
        }
    
        System.out.println(appleCount);
        System.out.println(orangeCount);
    }