Shortest Path from Car to Oasis
Updated
Problem statement
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[]) → intExamples
Example 1
grid = ["C..",".#.","..O"]return = 4One shortest path uses four orthogonal moves around the blocked center cell.
Example 2
grid = ["C#O","###","..."]return = -1Blocked cells separate the car from the oasis.
Example 3
grid = ["CO"]return = 1The 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
Cand exactly oneO.
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