Sort by

recency

|

3106 Discussions

|

  • + 0 comments

    Simple Python Soln

    def countApplesAndOranges(s, t, a, b, apples, oranges): c1 = c2 = 0 for i in apples: if i > 0: if (i + a) in range(s,t + 1): c1 += 1 for j in oranges: if j < 0: if (b + j) in range(s, t + 1): c2 += 1 print(c1,c2, sep="\n") if name == 'main':

  • + 0 comments

    Rust

    fn countApplesAndOranges(s: i32, t: i32, a: i32, b: i32, apples: &[i32], oranges: &[i32]) {
        
     let mut apple_count = 0;   
     let mut orange_count = 0;
        
     for ap in apples {
        let dis = a + ap;
        if dis >= s && dis <= t {
            apple_count += 1
        }
     }
     
     for or in oranges {
        let dis = b + or;  
        if dis >= s && dis <= t {
            orange_count += 1
        }
     }
     
    
  • + 0 comments

    Good challenge. Also, I found this tool that gives a very detailed analysis of my resume and suggests amazing improvements: www.autointerviewai.com/ats-score . You guys might wanna check it out!

  • + 0 comments
    function countApplesAndOranges(start: number, end: number, appleTree: number, orangeTree: number, apples: number[], oranges: number[]): void {
        let applesCount = 0, orangesCount = 0;
        
        for (let index = 0; index < Math.max(apples.length, oranges.length); index ++) {
            const applePosition = appleTree + apples?.[index];
            const orangePosition = orangeTree + oranges?.[index];
            
            if (!Number.isNaN(applePosition) && applePosition >= start && applePosition <= end) {
                applesCount++;
            }
            
            if (!Number.isNaN(orangePosition) && orangePosition >= start && orangePosition <= end) {
                orangesCount++;
            }
        }
        
        console.log(applesCount.toString());
        console.log(orangesCount.toString());
    }
    
  • + 0 comments

    python 3

    def countApplesAndOranges(s, t, a, b, apples, oranges):

    apples = sum(1 for d in apples if s <= a + d <= t)
    
    oranges = sum(1 for d in oranges if s <= b + d <= t)
    
    print(apples)
    print(oranges)