Algorithm · Bloomberg · Medium
Problem: Determine Whether a Gas Circuit Can Be Completed Two equally sized arrays, gas and cost, describe a circular set of stations: gas[i] gives the fuel available for collection at station i. cost[i] gives the fuel required to move from station i to station (i+1) % n. You can choose any station as your starting point, beginning with an empty tank. Whenever you reach a station, collect its fuel before driving onward to the following station. Return: an index that can…
Checking your access…