FastPrepShortest Path from Car to Oasis
Problems/Shortest Path from Car to Oasis

Shortest Path from Car to Oasis

Bloomberg LP logoBloomberg LP● MediumNEW GRADONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: The report asks for the fewest four-direction steps from a car to an oasis, and it confirms that plain BFS is the way. We chose the symbol for a blocked cell and the grid limits. These follow the similar fuel-grid problems from the same company, so the path search is not trivial and the problem can run. Our version is about 85% the same as the reported question.

A rectangular desert grid contains exactly one car C, exactly one oasis O, open ground ., and blocked cells #.

From an open cell, the car may move one cell up, down, left, or right. It may not leave the grid or enter a blocked cell.

Return the minimum number of moves needed to reach the oasis. Return -1 if the oasis is unreachable.

Function

shortestPathToOasis(grid: String[]) → int

Examples

Example 1

grid = ["C..",".#.","..O"]return = 4
grid
0120C..1.#.2..O

One shortest path uses four orthogonal moves around the blocked center cell.

Example 2

grid = ["C#O","###","..."]return = -1
grid
0120C#O1###2...

Blocked cells separate the car from the oasis.

Example 3

grid = ["CO"]return = 1
grid
010CO

The oasis is directly adjacent to the car.

Constraints

  • 1 <= grid.length <= 200.
  • 1 <= grid[i].length <= 200, and every row has the same length.
  • Every cell is one of C, O, ., or #.
  • The grid contains exactly one C and exactly one O.

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

  • Number of IslandsFleetx · ONSITE INTERVIEW
  • Minimum Time to Spread Through a GridAmazon · PHONE SCREEN · ONSITE INTERVIEW
  • Number of IslandsIntuit · ONSITE INTERVIEWIntuit interview questions
  • Rotting OrangesSalesforce · ONSITE INTERVIEWSalesforce interview questions
  • Minimum Time to Rot All OrangesMicrosoft · ONSITE INTERVIEWMicrosoft interview questions
  • Number of Islands with Diagonal ConnectivityGoogle · ONSITE INTERVIEWGoogle interview questions
  • Island Count and Maximum AreaOracle · ONSITE INTERVIEWOracle interview questions
  • Shortest Increasing Path to a TargetUber · ONSITE INTERVIEWUber interview questions
  • Find and Reconstruct a Binary-Matrix PathMeta · PHONE SCREEN · ONSITE INTERVIEWMeta interview questions
  • Rotting OrangesOtter.ai · ONSITE INTERVIEWOtter.ai interview questions

Interview reports that mention this question

  • Bloomberg Interview Questions, Level Not Reported: 65 Questions
  • Bloomberg Experienced Design & More: 126 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 Experienced SWE Interviews: 167 Questions (Part 1 of 2)
All Bloomberg LP interview questionsSee Bloomberg LP hiring insights
Saved
class Solution {
    public int shortestPathToOasis(String[] grid) {
        // Write your code here.
    }

}
Checking account…