Validate 3x3 Digit Windows
Reported by candidates from Matroid's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
The detail that matters in this Matroid OA, reported in August 2026, is the shape of the input: a matrix that's always exactly 3 rows tall, with digits only from 1 to 9. That turns a scary-sounding sliding window into a tiny counting check. For each of the n - 2 positions, you decide if nine cells hold every digit once. It's a math and counting problem wearing a matrix costume. If your mind goes blank mid-assessment, StealthCoder runs invisibly on your desktop as a safety net and hands you the solution in real time.
The problem
You are given numbers, a 3 x n matrix containing only digits from 1 through 9. Consider a 3 x 3 window that slides from left to right through numbers. It has n - 2 positions. For every position, determine whether the nine cells contain all numbers from 1 through 9, inclusive. Return a boolean array of length n - 2 in left-to-right window order. Its i-th element is true exactly when the i-th window contains all nine numbers, and false otherwise. Because each window contains exactly nine cells, a valid window contains each digit from 1 through 9 exactly once. A solution with time complexity no worse than O(numbers[0].length^3) fits within the execution time limit. Function solution(numbers: int[][]) → boolean[] Examples Example 1 numbers = [[1, 2, 3, 2, 5, 7], [4, 5, 6, 1, 7, 6], [7, 8, 9, 4, 8, 3]] return = [true, false, true, false] The first window contains every digit from 1 through 9, so its result is true. The second is missing 7 and contains 2 twice, so it is false. The third again contains all nine digits, so it is true. The final window is missing 9 and contains 7 twice, so it is false. Constraints numbers.length == 3 Every row of numbers has the same length n. n >= 3 1 <= numbers[row][col] <= 9
Reported by candidates. Source: FastPrep
Pattern and pitfall
The trick is that a window has exactly nine cells, so containing all of 1 through 9 means containing each digit exactly once. Build a set from the nine values and check its size is 9. Since every value is already between 1 and 9, a size of 9 guarantees a perfect match. Loop i from 0 to n - 3, gather numbers[r][i..i+2] for the three rows, and push true or false. That's O(n) with a constant of nine, far under the stated bound. The common pitfall is an off-by-one on the window count, which must be n - 2. Another is checking only the sum equals 45, which fails on inputs like two 1s and a missing 2 that still sum correctly. Use a set or a count array. If you freeze on the live OA, StealthCoder is the hedge that reads the problem and gives you working code.
Drill it cold or hedge it with StealthCoder. Either way, don't walk into the OA hoping you remember the trick.
You can drill Validate 3x3 Digit Windows cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. Made for the candidate who got the OA invite this morning and has 72 hours, not six months.
Get StealthCoderRelated leaked OAs
You've seen the question.
Make sure you actually pass Matroid's OA.
Matroid reuses patterns across OAs. Made for the candidate who got the OA invite this morning and has 72 hours, not six months. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Validate 3x3 Digit Windows FAQ
How hard is Validate 3x3 Digit Windows really?+
It's easy. The matrix is fixed at 3 rows, so every window is nine cells. You loop over columns, collect the values, and check for distinctness. The main risk isn't the algorithm, it's sloppy indexing at the edges of the matrix.
What's the trick to solve it fast?+
Since a window has nine cells and values are 1 to 9, all digits present means all are distinct. Put the nine values in a set and test that its size equals 9. No sorting or nested logic needed.
Can I just check that the window sum equals 45?+
No. Sum 45 is necessary but not sufficient. A window with duplicates and missing digits can still total 45, for example swapping a 1 and 3 for two 2s. Use a set or a frequency array to be safe.
How many windows should the output have?+
Exactly n - 2, where n is the number of columns. Window i covers columns i, i+1, and i+2 across all three rows. Loop i from 0 while i + 2 is less than n, and append one boolean per position.
How do I prepare in 48 hours for this kind of Matroid question?+
Write this one from scratch twice, once with a set and once with a count array. Then test edge cases: n equal to 3, all identical digits, and a valid window at the very end. That covers most fixed-size window problems.