FastPrepGrid Exploration
Problems/Grid Exploration

Grid Exploration

IMC Trading logoIMC Trading● MediumNEW GRADOA

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in an IMC Trading new grad online assessment. Our task is about 99% the same as the combined photographed reports. The earlier report gives the function interface, the size limits and more examples. Coordinates start at zero, as in the examples.

You are given a rectangular grid. Each character is - for an open cell or x for an obstacle.

Start at the unblocked cell (row_start, column_start) and reach the unblocked cell (row_end, column_end). All coordinates use zero-based row and column indices.

Each move travels one cell up, down, left, or right, stays inside the grid, and enters an open cell. Moving down or right costs 0; moving up or left costs 1. Cells may be revisited, and each move is charged according to its direction.

Return the minimum total cost. Return -1 if the target is unreachable. If the endpoints are identical, return 0.

Function

exploreGrid(grid: String[], row_start: int, column_start: int, row_end: int, column_end: int) → int

Examples

Example 1

grid = ["-----","---x-","--x-x","-----"]row_start = 2column_start = 3row_end = 1column_end = 4return = 5
grid
012340-----1---x-2--x-x3-----

Move down to (3,3), left twice to (3,1), up three times to (0,1), right three times to (0,4), then down to (1,4). Only the two left and three up steps are charged, for a total of 5.

Example 2

grid = ["---","---"]row_start = 0column_start = 0row_end = 1column_end = 2return = 0
grid
0120---1---

A route using only down and right reaches the target at zero cost.

Example 3

grid = ["---","---"]row_start = 1column_start = 2row_end = 0column_end = 0return = 3
grid
0120---1---

Any route needs at least one up step and two left steps. A direct route has cost 3.

Example 4

grid = ["-x--","-xx-","----","-x-x","-xx-"]row_start = 3column_start = 0row_end = 0column_end = 2return = 4
grid
01230-x--1-xx-2----3-x-x4-xx-

Go up once, right three times along row 2, up twice along column 3, then left once to (0,2). The three up steps and one left step cost 4.

Example 5

grid = ["-x-","-xx","---"]row_start = 2column_start = 0row_end = 0column_end = 2return = -1
grid
0120-x-1-xx2---

The destination (0,2) has blocked neighbors and cannot be reached.

Constraints

  • 1 <= n, m <= 1500, where n is the number of rows and m is the length of each row.
  • Every row has the same length.
  • Every character is - or x.
  • 0 <= row_start, row_end < n
  • 0 <= column_start, column_end < m
  • The starting and target cells are unblocked.

More IMC Trading Online Assessment questions

  • Earliest Meeting Start on a 24-Hour ClockOA · Seen Nov 2026
  • Grid Paths with Override PassesOA · Seen Oct 2026
  • Weighted LFU CacheOA · Seen Sep 2026
  • Rock JumpingOA · Seen Aug 2026
  • Stack Batch RemovalOA · Seen Aug 2026
  • Chain of CommandOA · Seen Aug 2026
  • Choose ContainersOA · Seen Aug 2026
  • Sub-matrix SumsOA · Seen Jul 2026
  • Sub-matrix SumsOA · Seen Jul 2026
  • Can Every Package Fit in a BoxOA · Seen Jul 2026

Similar questions at other companies

  • Drone Delivery with Battery Swap StationsCisco · OACisco interview questions
  • Shortest Travel Time in a Grid with Traffic LightsWaymo · PHONE SCREENWaymo interview questions
  • Fire Station Response BillLinkedIn · ONSITE INTERVIEWLinkedIn interview questions
  • Shortest Increasing Path to a TargetUber · ONSITE INTERVIEWUber interview questions
  • Minimum Distance to Return a BookGoogle · ONSITE INTERVIEWGoogle interview questions
  • Find and Reconstruct a Binary-Matrix PathMeta · PHONE SCREEN · ONSITE INTERVIEWMeta interview questions
  • Delivery Management SystemAkuna Capital · OAAkuna Capital interview questions
  • Minimize CommuteDatabricks · OA · PHONE SCREENDatabricks interview questions
  • Minimum MovesHarness · OA
  • Shortest Atom Action PathOpenAI · OAOpenAI interview questions

Interview reports that mention this question

  • IMC Trading OA: What It Tests (2026)

IMC Trading interview experiences

  • IMC Trading SWE OA and Video: 18 Experiences (Part 3 of 3)
  • IMC Trading SWE OA Questions: 22 Experiences (Part 2 of 3)
  • IMC SWE New Grad OA and Interviews: 58 Experiences (Part 1 of 3)
All IMC Trading interview questionsSee IMC Trading hiring insights
Saved
class Solution {
    public int exploreGrid(String[] grid, int row_start, int column_start, int row_end, int column_end) {
        // Write your code here.
    }

}
Checking account…