This multi-part question evaluates proficiency in grid-based pathfinding and shortest-path reasoning, debugging and incremental code extension, handling weighted or multi-target graph variants, ordered route planning across multiple targets, and array-based techniques for detecting duplicate and missing elements, situating it within the coding & algorithms domain that spans graph theory and array/data-structure problems. It is commonly asked to assess both practical implementation ability and algorithmic reasoning under constraints (such as large grids and input sizes), testing conceptual understanding of search and complexity trade-offs as well as practical application and optimization in code.
You are given two coding exercises from an interview loop.
You inherit an existing codebase that models a maze as a 2D grid and exposes a function to navigate from a start cell to a target cell.
'.'
= open cell
'#'
= wall
'S'
= start (exactly one)
'T'
= target (exactly one)
You will be asked to complete 4 sequential tasks, each building on the previous one:
T
is reachable from
S
.
S
to
T
(or
-1
if unreachable).
Clarify any ambiguous requirements with the interviewer. Implement the required functions and explain how you validated correctness.
You are given an m x n grid of integers:
0
= blocked cell
1
= empty traversable cell
>1
= a “tree” (or work item) with a height/value
You start at (0,0) and can move 4-directionally. You must visit and “process” all cells with value > 1 in increasing order of value. Processing a tree does not change traversability.
Return the minimum total number of steps to process all trees in order, or -1 if any required tree is unreachable at the time it must be processed.
You are given an array nums of length n that should contain every integer from 1 to n exactly once, but instead:
Return [duplicate, missing].
Assume m, n <= 10^3 for grid problems and n <= 10^5 for the array problem unless otherwise stated by the interviewer.