Question bank › Graphs Dfs
Dsa Graphs Dfs Medium

Longest Path in a Grid

Given a grid of integers, where each cell represents the height, find the length of the longest path that you can take from a cell to another cell where you can only move to a neighboring cell if its height is higher. The input format is as follows: Input: - First line: an integer n (1 ≤ n ≤ 100) - the number of rows. - Next n lines: each containing m (1 ≤ m ≤ 100) integers representing the grid heights. Output: - An integer representing the length of the longest path. Example: Input: 4 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 Output: 16

Key concepts

graphsdfsdynamic_programming

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.