Dsa
Hashing
Medium
The Tile Pattern Finder
In a digital image represented by a grid of characters, we want to find recurring patterns. A '2x2 texture' is a 2x2 square of characters. Count how many unique 2x2 textures appear more than once in the given grid.
Input Format:
- Line 1: Two integers R and C (rows and columns).
- Next R lines: C characters each.
Output Format:
- An integer representing the number of distinct 2x2 patterns that occur at least twice.
Example:
Input:
3 3
ABA
BAB
ABA
Output:
1
(Explanation: The 2x2 pattern [[A,B],[B,A]] appears 4 times, but it is only 1 unique pattern.)
Key concepts
hashinggridgeometry
Practise this out loud — free
Start a mock interview on THIS exact question — a voice AI interviewer opens with it, pushes back like a real onsite, then hands you an instant scorecard.
🎙 Practise this question now