Skip to content

Instantly share code, notes, and snippets.

@samarthsewlani
Created February 21, 2021 09:23
Show Gist options
  • Save samarthsewlani/c461ea4cd25cf62783c037a58e2844ec to your computer and use it in GitHub Desktop.
Save samarthsewlani/c461ea4cd25cf62783c037a58e2844ec to your computer and use it in GitHub Desktop.
Truck Tour HackerRank Solution
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