Question bank › Graphs Dfs
Dsa Graphs Dfs Medium

The Prism Grid

You are in a grid of size R x C where each cell contains an integer. You can move from a cell (r, c) to an adjacent cell (up, down, left, right) if and only if the value in the destination cell 'V_dest' and the current cell 'V_curr' satisfy the Prism Rule: (V_dest - V_curr) % 3 == 1. Starting from (0,0), how many unique cells can you reach? Input Format: - Line 1: R C. - Next R lines: C integers each. Output Format: - A single integer representing the count of reachable cells. Example: Input: 2 2 0 1 2 0 Output: 4 (Explanation: (0,0) is 0. Move to (0,1) is 1. (1-0)%3=1. From 1 move to (1,0) which is 2. (2-1)%3=1. From 2 move to (1,1) which is 0. (0-2)%3=1.)

Key concepts

graphs_dfsgrid_traversalmodular_arithmetic

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.