• + 1 comment

    JAVA

    public static void countApplesAndOranges(int s, int t, int a, int b, List<Integer> apples, List<Integer> oranges) {
            int noOfApples = 0;
            int noOfOranges = 0;
    
            apples = apples.stream().map(x -> x + a).collect(Collectors.toList());
            oranges = oranges.stream().map(x -> x + b).collect(Collectors.toList());
    
            for (int applePosi : apples) {
                if (applePosi >= s && applePosi <= t) {
                    noOfApples++;
                }
            }
    
            for (int orangePosi : oranges) {
                if (orangePosi >= s && orangePosi <= t) {
                    noOfOranges++;
                }
            }
    
            System.out.println(noOfApples);
            System.out.println(noOfOranges);
        }