Detect anagram in matrix

Last updated: June 10, 2026

Quick Overview

Given a matrix of characters, write a function to detect all occurrences of anagrams of a given target string within the matrix. The function should return the starting coordinates of each found anagram as a list of tuples. The search should consider all possible horizontal and vertical placements of the target string within the matrix.

Supabase
Coding & Algorithms
Software Engineer
Supabase
June 10, 2026
Software Engineer
Technical Screen
Coding & Algorithms
Medium

43

12

1,023 solved


Given a matrix of characters, write a function to detect all occurrences of anagrams of a given target string within the matrix. The function should return the starting coordinates of each found anagram as a list of tuples. The search should consider all possible horizontal and vertical placements of the target string within the matrix.

Supabase uses this problem in the Technical 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
  • 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
Edge cases and input validation
Dynamic programming and memoization
Binary search and divide and conquer
Hash maps and frequency counting
Time and space complexity analysis
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 happens if the input contains duplicates?
  • How would your solution change if the input was sorted?
  • What is the worst-case input for your solution?
  • How would you modify your solution to handle streaming input?
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 detecting anagrams of a target string within a character matrix, we can utilize a frequency counting approach. The key insight is that two strings are anagrams if they have the...

Approach
  1. Frequency Count: Create a frequency dictionary for the target string. For example, if the target string is 'abc', the frequency dictionary will be {'a': 1, 'b': 1, 'c': 1}.
  2. **Search Horizont...

Submit Your Answer
Markdown supported

Related Questions