Skip to content

Update 002. Apple and Orange.py #46

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 25 additions & 5 deletions Algorithms/02. Implementation/002. Apple and Orange.py
Original file line number Diff line number Diff line change
@@ -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)