PracHub
QuestionsPremiumLearningGuidesCheatsheetNEWCoaches
|Home/Coding & Algorithms/Snapchat

Compute longest increasing path in matrix

Last updated: Mar 29, 2026

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.

Related Interview 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)
Snapchat logo
Snapchat
Dec 8, 2025, 7:38 PM
Software Engineer
Onsite
Coding & Algorithms
3
0

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.

Comments (0)

Sign in to leave a comment

Loading comments...

Browse More Questions

More Coding & Algorithms•More Snapchat•More Software Engineer•Snapchat Software Engineer•Snapchat Coding & Algorithms•Software Engineer Coding & Algorithms
PracHub

Master your tech interviews with 7,500+ 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
  • Compare Platforms
  • Discord Community

Support

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

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.