• + 0 comments

    this is very simple question here are the solution of this problemStatement in java(8)

    public static void countApplesAndOranges(int s, int t, int a, int b, List<Integer> apples, List<Integer> oranges) {
        // Write your code here
    
        int countApple = 0;
        int countOrange = 0;
    
        for (int i = 0; i < apples.size(); i++) {
    
            if ((a + apples.get(i)) >= s && (a + apples.get(i)) <= t) {
                countApple++;
            }
    
        }
        for (int i = 0; i < oranges.size(); i++) {
            if ((oranges.get(i) + b) >= s && (oranges.get(i) + b) <= t) {
                countOrange++;
            }
        }
        System.out.println(countApple);
        System.out.println(countOrange);
    }