We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
i did the same way but initialised range only once
def countApplesAndOranges(s, t, a, b, apples, oranges):
house_length = range(s,t+1)
apple_tree_location =a
orange_tree_location =b
apple_house_hit_count=0
orange_house_hit_count=0
for fall_pos in apples:
if fall_pos+apple_tree_location in house_length:
apple_house_hit_count +=1
for fall_pos in oranges:
if fall_pos+orange_tree_location in house_length:
orange_house_hit_count +=1
print("{}\n{}".format(apple_house_hit_count,orange_house_hit_count))
it worked .
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Apple and Orange
You are viewing a single comment's thread. Return to all comments →
i did the same way but initialised range only once def countApplesAndOranges(s, t, a, b, apples, oranges): house_length = range(s,t+1) apple_tree_location =a orange_tree_location =b apple_house_hit_count=0 orange_house_hit_count=0 for fall_pos in apples: if fall_pos+apple_tree_location in house_length: apple_house_hit_count +=1 for fall_pos in oranges: if fall_pos+orange_tree_location in house_length: orange_house_hit_count +=1 print("{}\n{}".format(apple_house_hit_count,orange_house_hit_count))