Detect palindrome in matrix
Last updated: April 23, 2026
Quick Overview
Given a 2D matrix of characters, write a function to detect all occurrences of palindromic sequences in the matrix, considering horizontal, vertical, and diagonal directions. The function should return a list of starting coordinates for each detected palindrome, along with the palindrome itself. Each palindrome must be at least three characters long.
Doordash
April 23, 202657
10
104 solved
Given a 2D matrix of characters, write a function to detect all occurrences of palindromic sequences in the matrix, considering horizontal, vertical, and diagonal directions. The function should return a list of starting coordinates for each detected palindrome, along with the palindrome itself. Each palindrome must be at least three characters long.
This coding problem is frequently asked during Technical Screen at Doordash. The interviewer is testing your ability to translate a problem into clean, working code while discussing time and space complexity. Doordash 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
How to Approach This
- Clarify input constraints and edge cases before writing code.
- Walk through your approach verbally and confirm with the interviewer before coding.
- Start with a brute force solution, then optimize. Mention time and space complexity.
- Test your solution with examples, including edge cases like empty input or duplicates.
- Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
- How would you parallelize this solution?
- How would you test this solution thoroughly?
- Can you solve this iteratively instead of recursively (or vice versa)?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Problem Analysis
To detect palindromic sequences in a 2D matrix, we need to consider multiple directions: horizontally, vertically, and diagonally (both major and minor diagonals). The problem can be approached using ...
Approach
- Initialize: Create a list to store results and define possible directions for movement (right, down, down-right diagonal, down-left diagonal).
- Iterate through each cell in the matrix: ...