FastPrepGas Station
Problems/Gas Station

Gas Station

Bloomberg LP logoBloomberg LP● MediumNEW GRADPHONE SCREENONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in a Bloomberg new grad onsite interview. The report names the well-known Gas Station problem, number 134, from a Bloomberg campus-recruiting question bank. It notes that many questions may be changed a little, but it keeps no change to this one. Our version uses the standard Gas Station circuit and is about 70% the same as the reported question.

There are n gas stations on a circular route. gas[i] is the fuel available at station i, and cost[i] is the fuel needed to travel from station i to station (i + 1) mod n.

You start with an empty tank. Return the index of the station from which you can travel clockwise around the circuit exactly once without the tank becoming negative. Return -1 if no such station exists. If a solution exists, it is unique.

Function

canCompleteCircuit(gas: int[], cost: int[]) → int

Examples

Example 1

gas = [1,2,3,4,5]cost = [3,4,5,1,2]return = 3

Starting at station 3, the tank never becomes negative and returns to station 3 after visiting every station.

Example 2

gas = [2,3,4]cost = [3,4,3]return = -1

Total available fuel is less than the total travel cost, so no start can complete the circuit.

Example 3

gas = [5]cost = [4]return = 0

The single station supplies enough fuel for its only leg.

Constraints

  • 1 <= n == gas.length == cost.length <= 100000.
  • 0 <= gas[i], cost[i] <= 10000.
  • If a valid starting station exists, it is unique.

More Bloomberg LP Onsite Interview questions

  • Pascal's TrianglePHONE SCREEN · ONSITE INTERVIEW · Seen Dec 2026
  • Valid Triangle NumberPHONE SCREEN · ONSITE INTERVIEW · Seen Dec 2026
  • Collatz Conjecture with Shared MemoizationPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Word SearchOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • N-ary Index-Path Encoder and DecoderPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Top K Frequent WordsONSITE INTERVIEW · Seen Nov 2026
  • Trapping Rain WaterPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Design Browser HistoryPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
  • Mutable Stock Price Top KPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
  • Add Two Numbers IIPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026

Similar questions at other companies

  • Minimum Piano Hand Raises and Thumb PositionsGoogle · ONSITE INTERVIEWGoogle interview questions
  • Fair Capped Money DistributionGusto · PHONE SCREEN · ONSITE INTERVIEWGusto interview questions
  • Largest Number Below N from Reusable DigitsByteDance · PHONE SCREENByteDance interview questions
  • Tennis Court SchedulingAtlassian · PHONE SCREEN · ONSITE INTERVIEWAtlassian interview questions
  • Jump GamePaytm · PHONE SCREENPaytm interview questions
  • Minimum Station Tracks for a Train ScheduleBNSF Railway · ONSITE INTERVIEWBNSF Railway interview questions
  • Best Time to Buy and Sell Stock IIKotak Mahindra Bank · ONSITE INTERVIEWKotak Mahindra Bank interview questions
  • Minimize Total Weight After HalvingAmazon · ONSITE INTERVIEW
  • Remove the Fewest Magic BeansThe D.E. Shaw Group · PHONE SCREENThe D.E. Shaw Group interview questions
  • Capacity to Ship Packages Within DaysMicrosoft · OA · ONSITE INTERVIEWMicrosoft interview questions

Interview reports that mention this question

  • Bloomberg New Grad Coding Questions: 121 Questions (Part 2 of 2)
  • Bloomberg New Grad OOD Follow-ups: 14 Experiences (Part 3 of 5)

Bloomberg LP interview experiences

  • Bloomberg AI-Assisted Coding Round, All Levels: 14 Experiences
  • Bloomberg SWE Intern Interview Questions: 68 Questions
  • Bloomberg Interview Questions, Level Not Reported: 65 Questions
  • Bloomberg Experienced Design & More: 126 Questions (Part 2 of 2)
All Bloomberg LP interview questionsSee Bloomberg LP hiring insights
Saved
class Solution {
    public int canCompleteCircuit(int[] gas, int[] cost) {
        // Write your code here.
    }

}
Checking account…