Sort by

recency

|

3101 Discussions

|

  • + 0 comments

    Java

    public static void countApplesAndOranges(int s, int t, int a, int b, List<Integer> apples, List<Integer> oranges) {
        // Write your code here
        long countApples =apples.stream().map(apple->apple+a).filter(pos->pos>=s && pos<=t).count();
        long countOranges =oranges.stream().map(orange->orange+b).filter(pos->pos>=s && pos<=t).count();
        
        System.out.println(countApples+"\n"+countOranges);
    
        }
    
  • + 0 comments

    python a_count = 0 b_count = 0 for apple in apples: apple += a if apple <= t and apple >= s: a_count += 1 for orange in oranges: orange += b if orange <= t and orange >= s: b_count += 1 print(f"{a_count} \n{b_count}")

  • + 0 comments

    python a_count = 0 b_count = 0 for apple in apples: apple += a if apple <= t and apple >= s: a_count += 1 for orange in oranges: orange += b if orange <= t and orange >= s: b_count += 1 print(f"{a_count} \n{b_count}")

  • + 0 comments
    public static void countApplesAndOranges(int s, int t, int a, int b, List<int> apples, List<int> oranges)
        {
            var applesInside = apples.Where(ap => (ap + a) >= s && (ap + a) <= t).Count();
            var orangesInside = oranges.Where(or => (or + b) >= s && (or + b) <= t).Count();
            
            Console.WriteLine(applesInside);
            Console.WriteLine(orangesInside);
        }
    
  • + 0 comments
    public static void countApplesAndOranges(int s, int t, int a, int b, List<int> apples, List<int> oranges)
        {
            var applesInside = apples.Where(ap => (ap + a) >= s && (ap + a) <= t).Count();
            var orangesInside = oranges.Where(or => (or + b) >= s && (or + b) <= t).Count();
            
            Console.WriteLine(applesInside);
            Console.WriteLine(orangesInside);
        }