Detect permutation in matrix
Last updated: April 17, 2026
Quick Overview
Given a matrix of characters and a target string, determine if any row or column in the matrix contains a permutation of the target string. The function should return true if such a permutation exists, and false otherwise. The input will be a 2D array of characters and a string, and the output should be a boolean value.
Palantir
April 17, 2026122
7
211 solved
Given a matrix of characters and a target string, determine if any row or column in the matrix contains a permutation of the target string. The function should return true if such a permutation exists, and false otherwise. The input will be a 2D array of characters and a string, and the output should be a boolean value.
This coding problem is frequently asked during Technical Screen at Palantir. The interviewer is testing your ability to translate a problem into clean, working code while discussing time and space complexity. Palantir expects candidates to write production-quality code, not just solve the puzzle.
What the Interviewer Expects
- Identify the correct data structure and algorithm for the problem
- Write clean, bug-free code with proper variable naming
- Analyze time and space complexity correctly
- Handle basic edge cases (empty input, single element)
- Communicate your thought process while coding
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
- What is the worst-case input for your solution?
- Can you optimize the space complexity of your solution?
- 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 ProblemsSample Answer
Problem Analysis
We need to determine if any row or column in a given matrix contains a permutation of a target string. This suggests that we should focus on frequency counting because permutations have the same chara...
Approach
- Count the frequency of characters in the target string using a hash map.
- For example, for the target string 'abc', the frequency map would be {'a': 1, 'b': 1, 'c': 1}.
- **Iterate through...