From 16a8b5bbc11a58cec0e715255f9ec57fe11faab6 Mon Sep 17 00:00:00 2001 From: Rishabh Singh Chauhan <143814425+Rsc2414@users.noreply.github.com> Date: Sun, 20 Jul 2025 22:38:49 +0530 Subject: [PATCH] Update 002. Apple and Orange.py --- .../002. Apple and Orange.py | 30 +++++++++++++++---- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/Algorithms/02. Implementation/002. Apple and Orange.py b/Algorithms/02. Implementation/002. Apple and Orange.py index 2f8d2dc..87341bd 100644 --- a/Algorithms/02. Implementation/002. Apple and Orange.py +++ b/Algorithms/02. Implementation/002. Apple and Orange.py @@ -1,9 +1,29 @@ # Problem: https://www.hackerrank.com/challenges/apple-and-orange/problem # Score: 10 +# Read input values +s, t = map(int, input().split()) # House start and end point +a, b = map(int, input().split()) # Apple tree and orange tree position +m, n = map(int, input().split()) # Number of apples and oranges -s, t, a, b, m, n = map(int, input().split() + input().split() + input().split()) -apple = list(map(int, input().split())) -orange = list(map(int, input().split())) -print(sum(s <= a + i <= t for i in apple)) -print(sum(s <= b + i <= t for i in orange)) +# Distances apples fell from the apple tree +apples = list(map(int, input().split())) + +# Distances oranges fell from the orange tree +oranges = list(map(int, input().split())) + +# Count how many apples fell on the house +apple_count = 0 +for d in apples: + if s <= a + d <= t: # Final position of apple is within house range + apple_count += 1 + +# Count how many oranges fell on the house +orange_count = 0 +for d in oranges: + if s <= b + d <= t: # Final position of orange is within house range + orange_count += 1 + +# Print the results +print(apple_count) +print(orange_count)