FastPrepCar to Oasis with Gas Stations
Problems/Car to Oasis with Gas Stations

Car to Oasis with Gas Stations

Bloomberg LP logoBloomberg LP● HardFULLTIMEPHONE SCREENONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: A senior software engineer's report from a Bloomberg on-site day describes a grid question: a car on a desert map must reach an oasis, some cells are gas stations that hold gas to add to the tank, some cells are rocks, and the car starts with some gas. The report gives one map and two results for a small and a larger starting amount, but no limits and no written rules for how gas is spent or how a station works. Two shorter reports from other interviews mention a grid with fuel or gas stops only in passing, so they are not used for the rules.

Everything else here is our practice choice. Each move costs one unit, and a move is possible only while the tank holds at least one unit. Entering a station adds its gas once, and afterwards the cell is plain sand. There is no tank limit, and arriving at a station or the oasis with an empty tank is allowed. The car moves up, down, left or right. The function takes the map and the starting gas, and every cell is text. The grid is at most 15 by 15 with at most 8 stations, each holding 1 to 50, and the starting gas is 0 to 100.

The judged task matches the report at about 80%.

A desert is a grid desert of text cells. Each cell is one of:

  • "c": the car's starting cell.
  • "o": the oasis the car wants to reach.
  • ".": sand, which the car can drive on.
  • "r": a rock, which the car cannot enter.
  • a positive whole number such as "20": a gas station holding that many units of gas.

The car starts with gas units of gas in its tank. In one move it goes to the cell above, below, left or right. It cannot leave the grid. Each move costs 1 unit, so the car can make a move only when its tank holds at least 1 unit.

When the car enters a gas station, it takes all the gas there and adds it to its tank. A station gives its gas only the first time the car enters it; after that it is plain sand. The tank has no size limit. The car may arrive at a station or at the oasis with an empty tank.

Return true if the car can reach the oasis, and false otherwise.

Function

ride(desert: String[][], gas: int) → boolean

Examples

Example 1

desert = [[".",".",".","o"],[".","r",".","r"],[".","r","r","r"],["c",".",".","20"]]gas = 2return = false

The oasis is up and to the right of the car, and the only way there is the 6-move path up the left side and along the top. Two units of gas are not enough for that. The gas station 20 is 3 moves away (along the bottom row), and the car has only 2 units, so it cannot reach it either. The answer is false.

Example 2

desert = [[".",".",".","o"],[".","r",".","r"],[".","r","r","r"],["c",".",".","20"]]gas = 3return = true

With 3 units the car drives along the bottom row to the station: 3 moves, tank empty on arrival. It collects the 20 units. Then it drives back along the bottom row and up the left side and along the top to the oasis: 9 moves. The tank has 20, so the answer is true.

Example 3

desert = [["c","3",".",".",".","o"]]gas = 1return = false

The car moves onto the station (1 move, tank 0) and collects 3 units. The oasis is 4 moves from the station, but the tank has only 3. The station gives its gas only once, so the car cannot bounce back and forth to refill. The answer is false.

Example 4

desert = [["c","3",".",".",".","o"]]gas = 2return = true

The car moves onto the station (1 move, tank 1) and collects 3 units, so the tank holds 4. The oasis is 4 moves away, and the tank is empty exactly on arrival. Arriving with an empty tank counts, so the answer is true.

Constraints

  • 1 <= desert.length <= 15
  • 1 <= desert[i].length <= 15, and every row has the same length.
  • 0 <= gas <= 100
  • Every cell is "c", "o", ".", "r", or a whole number from 1 to 50 written without leading zeros (a gas station).
  • The grid has exactly one "c" and exactly one "o".
  • The grid has at most 8 gas stations.

More Bloomberg LP Onsite Interview questions

  • 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
  • Word SearchOA · PHONE 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
  • Decode StringPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
  • Minimum Replacements to Make Two Strings AnagramsPHONE SCREEN · ONSITE INTERVIEW · Seen Sep 2026
  • Currency Conversion RatePHONE SCREEN · ONSITE INTERVIEW · Seen Sep 2026

Similar questions at other companies

  • Competitive ForagingAkuna Capital · OAAkuna Capital interview questions
  • Escape the Haunted Castle with TreasuresPersona · OAPersona interview questions
  • Swim in Rising WaterUiPath · PHONE SCREEN
  • Shortest Grid Path with Obstacle EliminationsAmazon · ONSITE INTERVIEW
  • Choose the Next Minesweeper ActionRunloop · PHONE SCREEN
  • Shortest Grid Path with Obstacle EliminationGoogle · ONSITE INTERVIEWGoogle interview questions
  • Shortest Distance from All BuildingsWaymo · PHONE SCREENWaymo interview questions
  • Shortest Path in a Grid with Obstacles EliminationMercor · PHONE SCREENMercor interview questions
  • Shortest Path Visiting All NodesInMobi · ONSITE INTERVIEWInMobi interview questions
  • Sliding PuzzleNVIDIA · PHONE SCREENNVIDIA interview questions

Bloomberg LP interview experiences

  • Bloomberg SWE Phone Screen and Onsite: 1 Experience
  • Bloomberg SWE Phone Screens with Two Teams: 1 Experience
  • Bloomberg AI Interview, Hiring Level Not Reported: 2 Experiences
  • Bloomberg Experienced SWE AI Coding Interviews: 2 Experiences
  • Bloomberg New Grad AI-Assisted Coding Rounds: 3 Experiences
  • Bloomberg New Grad SWE AI-Assisted Coding Rounds: 1 Experience
All Bloomberg LP interview questionsSee Bloomberg LP hiring insights
Saved
class Solution {
    public boolean ride(String[][] desert, int gas) {
        // Write your code here.
    }
}
Checking account…