Fuel-Aware Grid Reachability
Updated
Problem statement
You have a tank whose capacity is fuelCapacity. It starts full. The rectangular grid contains exactly one start cell S, exactly one target cell T, open ground ., blocked cells #, and fuel cells G.
You may move one cell up, down, left, or right. Each move consumes one unit of fuel, so you may leave a cell only when at least one unit remains. You cannot enter a blocked cell. Entering a fuel cell immediately restores the tank to fuelCapacity; a fuel cell may refill the tank again on a later visit.
Return true if you can reach T, and return false otherwise. Reaching T with zero fuel remaining is allowed.
Function
canReachWithFuel(grid: String[], fuelCapacity: int) → booleanExamples
Example 1
grid = ["S..",".#G","...","..T"]fuelCapacity = 4return = trueThe start-to-target distance exceeds four moves, but the path can reach G in three moves, refill to four units, and then reach T.
Example 2
grid = ["S#T","..."]fuelCapacity = 3return = falseThe obstacle forces a four-move detour, and there is no fuel cell to extend the initial three units.
Example 3
grid = ["SGT"]fuelCapacity = 1return = trueThe first move spends the only fuel unit, entering G restores it, and the second move reaches T.
Constraints
1 <= grid.length <= 200.1 <= grid[i].length <= 200, and all rows have the same length.0 <= fuelCapacity <= 400.- Every cell is one of
S,T,.,#, orG. - The grid contains exactly one
Sand exactly oneT.
More Bloomberg LP Onsite Interview questions
- 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
- Decode StringPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
- Minimum Replacements to Make Two Strings AnagramsPHONE SCREEN · ONSITE INTERVIEW · Seen Sep 2026
Similar questions at other companies
- Number of IslandsFleetx · ONSITE INTERVIEW
- Matrix EscapeByteDance · PHONE SCREENByteDance interview questions
- Minimum Time to Spread Through a GridAmazon · PHONE SCREEN · ONSITE INTERVIEW
- Number of IslandsIntuit · ONSITE INTERVIEWIntuit interview questions
- Rotting OrangesSalesforce · ONSITE INTERVIEWSalesforce interview questions
- Max Area of Island Without Changing the GridFlexport · PHONE SCREENFlexport interview questions
- Minimum Time to Rot All OrangesMicrosoft · ONSITE INTERVIEWMicrosoft interview questions
- Reachable Exits in an Obstacle GridWhatNot · PHONE SCREENWhatNot interview questions
- Number of Islands with Diagonal ConnectivityGoogle · ONSITE INTERVIEWGoogle interview questions
- Island Count and Maximum AreaOracle · ONSITE INTERVIEWOracle interview questions
Interview reports that mention this question
- Bloomberg SWE Intern Interview Questions: 68 Questions
- Bloomberg Experienced SWE Interviews: 167 Questions (Part 1 of 2)
- Bloomberg New Grad Question Bank: 161 Questions (Part 1 of 2)
- Bloomberg New Grad Screens: 30 Experiences (Part 4 of 5)
- Bloomberg New Grad OOD Follow-ups: 14 Experiences (Part 3 of 5)
- Bloomberg New Grad SWE Interviews: 98 Experiences (Part 1 of 5)