Count longest subsequence in matrix

Last updated: March 8, 2026

Quick Overview

Given a matrix of integers, your task is to find the length of the longest increasing subsequence that can be formed by selecting elements from the matrix in a way that respects their row and column positions. The input will be a 2D array of integers, and the output should be a single integer representing the length of the longest increasing subsequence.

Plaid
Coding & Algorithms
Software Engineer
Plaid
March 8, 2026
Software Engineer
Technical Screen
Coding & Algorithms
Medium

4

8

3,568 solved


Given a matrix of integers, your task is to find the length of the longest increasing subsequence that can be formed by selecting elements from the matrix in a way that respects their row and column positions. The input will be a 2D array of integers, and the output should be a single integer representing the length of the longest increasing subsequence.

This coding problem is frequently asked during Technical Screen at Plaid. The interviewer is testing your ability to translate a problem into clean, working code while discussing time and space complexity. Plaid expects candidates to write production-quality code, not just solve the puzzle.

What the Interviewer Expects
  • Recognize the underlying problem pattern (sliding window, two pointers, BFS/DFS, etc.)
  • Discuss multiple approaches and trade-offs before coding
  • Implement an optimal solution with clean, production-quality code
  • Handle all edge cases including boundary conditions and invalid input
  • Optimize both time and space complexity with clear justification
  • Test your solution systematically with well-chosen examples
Key Topics to Cover
Tree structures and recursion
Common algorithm patterns (sliding window, two pointers, BFS/DFS)
Data structure selection and trade-offs
Graph algorithms and traversal
Dynamic programming and memoization
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
  • How would you modify your solution to handle streaming input?
  • How would you test this solution thoroughly?
  • How would you parallelize this solution?
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Practice DSA Problems
Sample Answer
Problem Analysis

To solve the problem of finding the longest increasing subsequence in a matrix while respecting row and column positions, we can identify that this is a variation of the Longest Increasing Subsequence...

Approach
  1. Initialization: Create a 2D array dp of the same dimensions as the input matrix, initialized to 1. Each element in dp[i][j] represents the length of the longest increasing subsequence that ...

Submit Your Answer
Markdown supported

Related Questions