FastPrepGrid Traversal (Infrastructure Automation Internship)
Problems/Grid Traversal (Infrastructure Automation Internship)

Grid Traversal (Infrastructure Automation Internship)

Snowflake logoSnowflake● HardINTERNOA

Updated Jul 2026

QuestionFunctionExamplesConstraints

Problem 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[]) → int

Examples

Example 1

grid = ["S#", "#E"]return = -1
grid
010S#1#E

Neither adjacent landing cell is traversable, so the destination cannot be reached.

Example 2

grid = ["S******", "#######", "######*", "######E"]return = 4
grid
01234560S******1#######2######*3######E

An optimal route uses four jumps:

  1. Jump from (0, 0) to (0, 5).
  2. Continue right from (0, 5) to (0, 6).
  3. Jump down from (0, 6) to (2, 6).
  4. Continue down by one cell to (3, 6), the destination.

Example 3

grid = ["S****#", "**#***", "*****#", "*#*#**", "#****E"]return = 5
grid
0123450S****#1**#***2*****#3*#*#**4#****E

An optimal route is:

  1. Jump from (0, 0) to (0, 3).
  2. Continue right by one cell to (0, 4).
  3. Jump down to (3, 4).
  4. Continue down by one cell to (4, 4).
  5. Jump right by one cell to (4, 5).

The route uses 5 jumps.

Constraints

  • 2 ≤ n, m ≤ 100
  • Every row contains only *, #, S, and E.
  • The grid contains exactly one S and exactly one E.

More Snowflake interview questions

  • Minimum StackPHONE SCREEN · Seen Nov 2026
  • Design In-Memory File SystemPHONE SCREEN · Seen Nov 2026
  • Merge Two Binary TreesPHONE SCREEN · Seen Nov 2026
  • Connect Four from the Last MovePHONE SCREEN · Seen Nov 2026
  • Minimum Edits to a Perfect Binary TreePHONE SCREEN · Seen Nov 2026
  • Parallel Courses IIIONSITE INTERVIEW · Seen Nov 2026
  • Safest Shortest Path Through a GridOA · Seen Nov 2026
  • Configurable Per-Client Token BucketsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Find Valid SET Card TriplesOA · PHONE SCREEN · Seen Nov 2026
  • LFU CacheOA · ONSITE INTERVIEW · Seen Nov 2026

Similar questions at other companies

  • Minimum Grid InconvenienceAmazon · OA
  • Competitive ForagingAkuna Capital · OAAkuna Capital interview questions
  • Drone Delivery with Battery Swap StationsCisco · OACisco interview questions
  • Escape the Haunted Castle with TreasuresPersona · OAPersona interview questions
  • Avoiding the Obstacles (IMC Sydney 🦪)IMC Trading · OAIMC Trading interview questions
  • Find Maximum DistanceWells Fargo · OAWells Fargo interview questions
  • Minimize CommuteDatabricks · OA · PHONE SCREENDatabricks interview questions
  • Simulate Orchard Rot SpreadAirbnb · OAAirbnb interview questions
  • Simulate Orchard Rot SpreadCapital One · OACapital One interview questions
  • Shortest Path in a Binary MatrixGoogle · OAGoogle interview questions

Snowflake interview experiences

  • Snowflake AI Coding Interview, Experienced Hires: 3 Experiences
All Snowflake interview questionsSee Snowflake hiring insights
Saved
class Solution {
    public int getMinJumps(String[] grid) {
      // write your code here
    }

}
Checking account…