Created
February 21, 2021 09:23
-
-
Save samarthsewlani/c461ea4cd25cf62783c037a58e2844ec to your computer and use it in GitHub Desktop.
Truck Tour HackerRank Solution
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
n=int(input()) | |
petrol,distance=[],[] | |
for i in range(n): | |
p,d=[int(x) for x in input().split()] | |
petrol.append(p),distance.append(d) | |
start,xsum=0,0 | |
for i in range(n): | |
xsum+=petrol[i]-distance[i] #Calculating the difference and adding to the sum | |
if xsum<0: #If sum becomes negative, that means we cannot complete the loop | |
start=i+1 #So start from the next index | |
xsum=0 #Reset the sum | |
print(start) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment