Sort by

recency

|

3095 Discussions

|

  • + 0 comments

    public static void countApplesAndOranges(int s, int t, int a, int b, List apples, List oranges) { // Write your code here int noOfApple = 0; for(Integer ap: apples){ int dist = ap+a; if(dist >= s && dist<=t){ noOfApple++; } } int noOfOrange = 0; for(Integer or: oranges){ int dist = or+b; if(dist >= s && dist<=t){ noOfOrange++; } }

        System.out.println(noOfApple);
        System.out.println(noOfOrange);
    }````
    
  • + 0 comments
    def countApplesAndOranges(s, t, a, b, apples, oranges):
    # Write your code here in Python3
    apples_loc = []
    orange_loc = []
    for i in apples:
        apples_loc.append(a + i)
    for i in oranges:
        orange_loc.append(b + i)
        apple_count = 0
    orange_count = 0
    for i in apples_loc:
        if i >= s and i <= t:
            apple_count += 1
    
    for i in orange_loc:
        if i >= s and i <= t:
            orange_count += 1
    
    
    print(apple_count)
    print(orange_count)
    
  • + 0 comments
    void countApplesAndOranges(int s, int t, int a, int b, vector<int> apples, vector<int> oranges)
    {
        int appleCount = 0;
        int orangeCount = 0;
        for(int i = 0; i < apples.size(); i++)
        {
            apples[i] += a;
            if(apples[i] >= s && apples[i] <= t)
            {
                appleCount++;
            }
        }
        for(int i = 0; i < oranges.size(); i++)
        {
            oranges[i] += b;
            if(oranges[i] >= s && oranges[i] <= t)
            {
                orangeCount++;
            }
        }
        cout << appleCount << endl;
        cout << orangeCount << endl;
    }
    
  • + 1 comment

    Here i use c++ 20, what do you think guys?

    void countApplesAndOranges(int s, int t, int a, int b, vector apples, vector oranges) { int sumApple = 0; int sumOrange = 0;

    for (int i = 0; i < apples.size(); i++) {
        apples[i] += a;
        if (apples[i] >= s && apples[i] <= t ) {
            sumApple++;
        }
    }
    for (int j = 0; j < oranges.size(); j++) {
        oranges[j] += b;
        if (oranges[j] >= s && oranges[j] <= t) {
            sumOrange++;
        }
    }
    cout << sumApple << "\n" << sumOrange << endl; 
    

    }

  • + 0 comments

    func countApplesAndOranges(s: Int, t: Int, a: Int, b: Int, apples: [Int], oranges: [Int]) -> Void { let appleNewPos = apples.map { val in return val+a }.filter { val in val>=s && val<=t } let orangeNewPos = oranges.map { val in return val+b }.filter { val in val>=s && val<=t } print("(appleNewPos.count)") print("(orangeNewPos.count)") }