Apple and Orange

I have been applying to different internships lately and have been referred to hackerrank through many of them so I decided why not add and talk about my solutions to some of the challenges.

This problem is called Apple and Orange and the whole point is to print the number of apples and oranges that fall from Sam’s house.

Here is the problem:

appleOrange

#!/bin/python3

import sys

#given

s,t = input().strip().split(' ')
s,t = [int(s),int(t)]
a,b = input().strip().split(' ')
a,b = [int(a),int(b)]
m,n = input().strip().split(' ')
m,n = [int(m),int(n)]
apple = [int(apple_temp) for apple_temp in input().strip().split(' ')]
orange = [int(orange_temp) for orange_temp in input().strip().split(' ')]

#my code

count = 0
for ap in apple:
     temp = a+ap
     if temp <= t and temp >=s:
         count = count + 1 
print (count)

count = 0
for ora in orange:
    temp = b+ora
    if temp <= t and temp >=s:
         count = count + 1 
print (count)

This problem is fairly simple I used two for loops since the array size for apple and orange can differ and I had to print the total apple and total orange.

 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s