Grid Traversal (Infrastructure Automation Internship)
Learn this problemProblem statement
Hackerland is represented by a grid with n rows and m columns. Empty cells are marked *, blocked cells are marked #, the start is marked S, and the destination is marked E.
A traveler may jump any positive integer length in one of four directions: up, down, left, or right. If a jump has length greater than 1, the next jump must continue in the same direction. A jump of length 1 releases this restriction, so the following jump may change direction. The last jump in the route must have length 1.
A jump may pass over blocked cells, but its starting and ending cells must be traversable. Determine the minimum number of jumps needed to reach E from S, or return -1 if no valid route exists.
Complete getMinJumps with String[] grid.
Returns: int, the minimum number of jumps, or -1 when the destination is unreachable.
Function
getMinJumps(grid: String[]) → intExamples
Example 1
grid = ["S#", "#E"]return = -1Neither adjacent landing cell is traversable, so the destination cannot be reached.
Example 2
grid = ["S******", "#######", "######*", "######E"]return = 4An optimal route uses four jumps:
- Jump from
(0, 0)to(0, 5). - Continue right from
(0, 5)to(0, 6). - Jump down from
(0, 6)to(2, 6). - Continue down by one cell to
(3, 6), the destination.
Example 3
grid = ["S****#", "**#***", "*****#", "*#*#**", "#****E"]return = 5An optimal route is:
- Jump from
(0, 0)to(0, 3). - Continue right by one cell to
(0, 4). - Jump down to
(3, 4). - Continue down by one cell to
(4, 4). - Jump right by one cell to
(4, 5).
The route uses 5 jumps.
Constraints
2 ≤ n, m ≤ 100- Every row contains only
*,#,S, andE. - The grid contains exactly one
Sand exactly oneE.
More Snowflake problems
- Minimum N-ary Tree Depth DeletionsPHONE SCREEN · Seen Jul 2026
- Simulate a Queued Multi-Rule Rate LimiterPHONE SCREEN · Seen Jul 2026
- Minimum Clicks Between Wiki PagesOA · Seen Jul 2026
- Closest Target CharacterPHONE SCREEN · Seen Jul 2026
- Horizontal Pod AutoscalerOA · Seen Jul 2026
- Minimum HeightOA · Seen Jul 2026
- Vowel SubstringOA · Seen Jun 2026
- String Formation (Also for AI/ML Software Engineer Intern :)OA · Seen Jun 2026