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
Coding & Algorithms
Software Engineer
Palantir
April 17, 2026
Software Engineer
Technical Screen
Coding & Algorithms
Easy

122

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
Dynamic programming and memoization
Graph algorithms and traversal
Common algorithm patterns (sliding window, two pointers, BFS/DFS)
Hash maps and frequency counting
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
  • 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 Problems
Sample 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
  1. 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}.
  2. **Iterate through...

Submit Your Answer
Markdown supported

Related Questions