old_contents: # https://www.interviewbit.com/problems/gas-station/
  
  
  class Solution:
      def canCompleteCircuit(self, gas, cost):
          n = len(gas)
          gas = gas*2
          cost = cost*2
  
          for start in xrange(n):
              fuel = 0
              for i in xrange(start, n+1):
                  fuel += gas[i]
                  if fuel < cost[i]:
                      break
              else:
                  return start
          return -1
  
  
  if '__main__' == __name__:
      gas = [1, 2]
      cost = [2, 1]
      solution = Solution()
      print solution.canCompleteCircuit(gas, cost)
  
new_contents: # https://www.interviewbit.com/problems/gas-station/
  
  
  class Solution:
      def canCompleteCircuit(self, gas, cost):
          n = len(gas)
          gas = gas*2
          cost = cost*2
  
          for start in xrange(n):
              fuel = 0
              for i in xrange(start, start+n+1):
                  fuel += gas[i]
                  fuel -= cost[i]
                  if fuel < 0:
                      break
              else:
                  return start
          return -1
  
  
  if '__main__' == __name__:
      gas = [959, 329, 987, 951, 942, 410, 282, 376, 581, 507, 546, 299, 564, 114, 474, 163, 953, 481, 337, 395, 679, 21, 335, 846, 878, 961, 663, 413, 610, 937, 32, 831, 239, 899, 659, 718, 738, 7, 209]
      cost = [862, 783, 134, 441, 177, 416, 329, 43, 997, 920, 289, 117, 573, 672, 574, 797, 512, 887, 571, 657, 420, 686, 411, 817, 185, 326, 891, 122, 496, 905, 910, 810, 226, 462, 759, 637, 517, 237, 884]
      solution = Solution()
      print solution.canCompleteCircuit(gas, cost)
  
subject: add start value to loop counter