diff --git a/HackerRank-Apple and Orange/Apple_and_Orange.py b/HackerRank-Apple and Orange/Apple_and_Orange.py index f5bad10..250684e 100644 --- a/HackerRank-Apple and Orange/Apple_and_Orange.py +++ b/HackerRank-Apple and Orange/Apple_and_Orange.py @@ -8,42 +8,51 @@ # Complete the countApplesAndOranges function below. def countApplesAndOranges(s, t, a, b, apples, oranges): + # Initialize counters for apples and oranges that fall within the house's range [s, t]. acount = 0 bcount = 0 + + # Iterate through the apples' positions. for i in range(len(apples)): - temp = a+apples[i] - if(temp in range(s,t+1)): - acount+=1 + # Calculate the actual position of the apple relative to the tree a. + temp = a + apples[i] + # Check if the apple's position falls within the house's range [s, t]. + if temp in range(s, t + 1): + # If the apple falls within the house's range, increment the apple counter. + acount += 1 + + # Iterate through the oranges' positions. for i in range(len(oranges)): - temp = b+oranges[i] - if(temp in range(s,t+1)): - bcount+=1 - print (acount) - print (bcount) - - + # Calculate the actual position of the orange relative to the tree b. + temp = b + oranges[i] + # Check if the orange's position falls within the house's range [s, t]. + if temp in range(s, t + 1): + # If the orange falls within the house's range, increment the orange counter. + bcount += 1 + + # Print the final count of apples and oranges that fall within the house's range. + print(acount) + print(bcount) if __name__ == '__main__': + # Read the input for the house's range [s, t]. st = input().split() - s = int(st[0]) - t = int(st[1]) + # Read the input for the positions of trees a and b. ab = input().split() - a = int(ab[0]) - b = int(ab[1]) + # Read the input for the number of apples and oranges. mn = input().split() - m = int(mn[0]) - n = int(mn[1]) + # Read the input for the positions of apples and oranges as lists. apples = list(map(int, input().rstrip().split())) - oranges = list(map(int, input().rstrip().split())) + # Call the countApplesAndOranges function with the given inputs. countApplesAndOranges(s, t, a, b, apples, oranges) pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy