Answers for "apple and orange hackerrank solution in c++"

C++
0

Apple and Orange hackerrank

static void countApplesAndOranges(int s, int t, int a, int b, int[] apples, int[] oranges) {
    int appleCount = 0;
    int orangeCount = 0;
    for(int i:apples){
        if(s<=i+a && i+a<=t)
            appleCount++;
    }
    for (int j : oranges) {
        if (s <= j + b && j+b <= t)
            orangeCount++;
    }
    System.out.println(appleCount);
    System.out.println(orangeCount);

}
Posted by: Guest on April-19-2021
0

apple and orange hackerrank solution in c++

#include<iostream>
using namespace std;
 
int main()
{
      int s,t,a,b,m,n;
    cin>>s>>t>>a>>b>>m>>n;
    int arr[m];
    int arr1[n];
    int apple=0;
    int orange=0;
   

    for(int i=0;i<m;i++){
        cin>>arr[i];
        if(a+arr[i]>=s && a+arr[i]<=t){
            apple++;
        }
    }


     for(int i=0;i<n;i++){
        cin>>arr1[i];
        if(b+arr1[i]>=s && b+arr1[i]<=t){
            orange++;
        }
    }
    cout<<apple<<endl<<orange<<endl;



}
Posted by: Guest on June-14-2020

Code answers related to "apple and orange hackerrank solution in c++"

Browse Popular Code Answers by Language