Detect permutation in matrix

Last updated: January 19, 2026

Quick Overview

Given a 2D matrix of characters and a string, determine if any of the rows or columns in the matrix contain a permutation of the given string. The function should return true if at least one permutation is found, and false otherwise. The input will consist of a matrix represented as a list of lists and a target string, with the output being a boolean value.

Stripe
Coding & Algorithms
Software Engineer
Stripe
January 19, 2026
Software Engineer
Phone Screen
Coding & Algorithms
Hard

1

10

803 solved


Given a 2D matrix of characters and a string, determine if any of the rows or columns in the matrix contain a permutation of the given string. The function should return true if at least one permutation is found, and false otherwise. The input will consist of a matrix represented as a list of lists and a target string, with the output being a boolean value.

Stripe uses this problem in the Phone Screen to evaluate your algorithmic thinking. They expect you to discuss multiple approaches, analyze trade-offs between them, and implement the optimal solution with clean, readable code.

What the Interviewer Expects
  • Quickly identify the optimal approach and its theoretical basis
  • Handle complex algorithm design with multiple interacting components
  • Write concise, elegant code under time pressure
  • Prove correctness of your approach and discuss alternative solutions
  • Optimize beyond the obvious: discuss constant factor improvements
  • Address follow-up variations and explain how the solution generalizes
Key Topics to Cover
Hash maps and frequency counting
Sorting and searching
Dynamic programming and memoization
Data structure selection and trade-offs
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
  • Can you solve this iteratively instead of recursively (or vice versa)?
  • How would you parallelize this solution?
  • What is the worst-case input for your 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 detect if any row or column in a 2D matrix contains a permutation of a given string, we can leverage the concept of frequency counting using hash maps. This problem can be viewed as a variation of ...

Approach
  1. Frequency Count of Target String: Create a frequency dictionary for the characters in the target string. For example, for the string 'abc', the frequency dictionary will be `{'a': 1, 'b': 1, 'c...

Submit Your Answer
Markdown supported

Related Questions