PracHub
QuestionsCoachesLearningGuidesInterview Prep

Quick Overview

This question evaluates algorithmic problem-solving skills in graph traversal and dynamic programming on matrices, measuring understanding of state representation and performance trade-offs in grid-based searches within the Coding & Algorithms domain.

  • hard
  • Snapchat
  • Coding & Algorithms
  • Software Engineer

Compute longest increasing path in matrix

Company: Snapchat

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: hard

Interview Round: Onsite

You are given an `m x n` grid (matrix) of integers `grid`, where `m >= 1` and `n >= 1`. A **path** in the matrix is a sequence of cells where: - You may move from a cell only to one of its 4 neighbors: up, down, left, or right (no diagonals). - Each step must go to a cell with a **strictly larger** value than the current cell. The length of a path is the number of cells in the path. **Task** Return the length of the **longest** strictly increasing path that can be found in the matrix. You may start the path at any cell. **Example** For example, given: - `grid = [[9, 9, 4], [6, 6, 8], [2, 1, 1]]` One of the longest increasing paths is `1 → 2 → 6 → 9`, so the answer is `4`. **Constraints** - `1 <= m, n <= 200` - `-10^9 <= grid[i][j] <= 10^9` Your solution should be efficient enough to handle the largest inputs within typical interview time limits.

Quick Answer: This question evaluates algorithmic problem-solving skills in graph traversal and dynamic programming on matrices, measuring understanding of state representation and performance trade-offs in grid-based searches within the Coding & Algorithms domain.

Return the length of the longest path moving 4-directionally to strictly larger values.

Constraints

  • grid is non-empty

Examples

Input: ([[9, 9, 4], [6, 6, 8], [2, 1, 1]],)

Expected Output: 4

Explanation: Prompt example.

Input: ([[1]],)

Expected Output: 1

Explanation: Single cell.

Input: ([[3, 4, 5], [3, 2, 6], [2, 2, 1]],)

Expected Output: 4

Explanation: Path 3-4-5-6.

Hints

  1. DFS with memoization turns overlapping path searches into one result per cell.
Last updated: Jun 27, 2026

Loading coding console...

PracHub

Master your tech interviews with 8,000+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities
  • Student Access

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • AI Coding Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.

Related Coding Questions

  • Determine Whether Courses Can Be Completed - Snapchat (medium)
  • Solve Decimal Coin Change - Snapchat (medium)
  • Find Maximum Island Perimeter - Snapchat (medium)
  • Solve Three Algorithmic Tasks - Snapchat (hard)
  • Implement a Timestamped Counter - Snapchat (medium)