Question bank › Backtracking
Dsa Backtracking Medium

Grid Sum Quest

Given a 4x4 grid of integers, find the number of unique paths starting from the top-left (0,0) and ending at the bottom-right (3,3) such that the sum of all numbers visited on the path is exactly S. You can move Up, Down, Left, or Right. You cannot visit the same cell twice in a single path. Input: The first line is the target sum S. The next 4 lines contain 4 integers each representing the grid. Example: Input: 10 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 Output: 0 (Explanation: The shortest path is 7 cells long, minimum sum is 7. No path of sum 10 exists from (0,0) to (3,3) in this grid.)

Key concepts

backtrackinggrid traversalpathfinding

Practise this out loud — free

Start a mock interview on THIS exact question — a voice AI interviewer opens with it, pushes back like a real onsite, then hands you an instant scorecard.

🎙 Practise this question now
Part of InterviewLab's verified interview question bank. We show the prompt and concepts to practise with — never a copy-paste solution.