2.2.4 Apples And Oranges Codehs
-
- def countApplesAndOranges(s, t, a, b, apples, oranges):
-
Write your code hither
- countA=0
- countO=0
- for i in range(len(apples)):
- sum=a+apples[i]
- if sum>=southward and sum<=t:
- countA+=1
- print(countA)
- for i in range(len(oranges)):
- sum=b+oranges[i]
- if sum>=south and sum<=t:
- countO+=1
- impress(countO)nd sum<=t: countO+=i print(countO)
-
c++ :
void countApplesAndOranges ( int due south , int t , int a , int b , vector < int > apples , vector < int > oranges ) { int apple = 0 ; int orangish = 0 ; for ( int i = 0 ; i < apples . size (); i ++ ) { if ( apples [ i ] + a >= due south && apples [ i ] + a <= t ) ++ apple ; } for ( int j = 0 ; j < oranges . size (); j ++ ) { if ( oranges [ j ] + b <= t && oranges [ j ] + b >= southward ) ++ orange ; } cout << apple tree << endl ; cout << orange ; }
-
C# int resultApple = 0; int resultOrange = 0;
for (int i = 0; i < apples.Count; i++) { if (a + apples[i] >= south && a + apples[i] <= t) resultApple++; } for (int i = 0; i < oranges.Count; i++) { if (b + oranges[i] <= t && b + oranges[i] >= due south) resultOrange++; } Console.WriteLine($"{resultApple} \n{resultOrange}");
-
> Simple Python Solution
def countApplesAndOranges ( s , t , a , b , apples , oranges ) : # Write your lawmaking here count_apple = 0 count_orrange = 0 ans = [] for i in apples : alphabetize = i + a if index >= s and index <= t : count_apple += i ans . suspend ( count_apple ) for j in oranges : index1 = j + b if index1 >= s and index1 <= t : count_orrange += 1 ans . append ( count_orrange ) for i in ans : print ( i )
-
Mod C++
void countApplesAndOranges ( int s , int t , int a , int b , vector < int > apples , vector < int > oranges ) { cout << count_if ( apples . begin (), apples . cease (), [ a , s , t ]( int dist ) { return ( dist + a >= s ) && ( dist + a <= t );}) << endl << count_if ( oranges . begin (), oranges . end (), [ b , s , t ]( int dist ) { return ( dist + b >= southward ) && ( dist + b <= t );}); }
2.2.4 Apples And Oranges Codehs,
Source: https://www.hackerrank.com/challenges/apple-and-orange/forum
Posted by: christensenplousee.blogspot.com
Sort 2303 Discussions , Past:
Please Login in order to mail a annotate