Sort by

recency

|

3031 Discussions

|

  • + 0 comments
    public static void countApplesAndOranges(int s, int t, int a, int b, List<int> apples, List<int> oranges)
        {
                int appleIncCount =0;
                int orangeIncCount =0;
                
                for(int i=0;i<apples.Count;i++){
                    if((apples[i] + a) >= s && (apples[i] + a) <= t ){
                        appleIncCount++;
                    }
                }
                
                 for(int i=0;i<oranges.Count;i++){
                    if((oranges[i] + b) >= s && (oranges[i] + b) <= t ){
                        orangeIncCount++;
                    }
                }
                Console.WriteLine(appleIncCount);
                Console.WriteLine(orangeIncCount);
        }
    
  • + 0 comments

    RUST:

    fn countApplesAndOranges(s: i32, t: i32, a: i32, b: i32, apples: &[i32], oranges: &[i32]) {
        let apple_count = apples.iter().filter(|&&apple| (s..=t).contains(&(a + apple))).count();
        let orange_count = oranges.iter().filter(|&&orange| (s..=t).contains(&(b + orange))).count();
    
        println!("{}", apple_count);
        println!("{}", orange_count);
    }
    
  • + 0 comments

    On `javascript solution {

    let applesInHome = 0; let orangesInHome = 0; let i = 0;

    while (i < apples.length || i < oranges.length) {
        if (i < apples.length && apples[i] + a >= s && apples[i] + a <= t) {
            applesInHome++;
        }
        if (i < oranges.length && oranges[i] + b >= s && oranges[i] + b <= t) {
            orangesInHome++;
        }
        i++; 
    }
    
    console.log(applesInHome);
    console.log(orangesInHome);
    
  • + 0 comments

    Here is my c++ solution, you can see the explanation here : https://youtu.be/YJVWinC21Fg

    void countApplesAndOranges(int s, int t, int a, int b, vector<int> apples, vector<int> oranges) {
        int orange = 0, apple = 0;
        for(int app: apples) if(app + a >= s && app + a <=t) apple++;
        for(int orr: oranges) if(orr + b >= s && orr + b <=t) orange++;
        cout << apple << endl << orange;
    }
    
  • + 0 comments

    Python3##

    def countApplesAndOranges(s, t, a, b, apples, oranges): apple_count = 0 orange_count = 0

    for i in apples:
        k = a + i
        if t >= k >= s:
            apple_count += 1
    for i in oranges:
        k = b + i
        if s <= k <= t:
            orange_count += 1
    print(apple_count)
    print(orange_count)