Accepted solution

Apple and Orange(Hacker Rank)

Open original problem
Source code

// Complete the countApplesAndOranges function below.

void countApplesAndOranges(int s, int t, int a, int b, vector<int> apples, vector<int> oranges)

 {

 

   int countApple=0,countOrange=0;

   for(int i=0;i<apples.size();i++)

   {

      int pos = a +(apples[i]);

      if(pos>=s && pos<=t)

      {

          countApple++;

      }

   }

   for(int i=0;i<oranges.size();i++)

   {

     int pos = b +(oranges[i]);

      if(pos>=s && pos<=t)

      {

          countOrange++;

      }

   }

   cout<<countApple<<endl<<countOrange<<endl;

 

}
Join the discussion

Add your comment