Fill and Sort Packed Missing-Number Grids
Reported by candidates from ZipRecruiter's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
The mistake that sinks a first attempt on this ZipRecruiter OA, reported in February 2022, is sorting by the wrong key. You fill the grids, then sort them by what exactly? The statement says "sort the logical grids by that numeric value", and Example 1 is confusing because the filled grids look identical. It's a sorting problem wrapped in a 4 by 4 slicing exercise. Nothing here is hard, but the packing format makes it easy to botch indices under time pressure. If you blank on the slicing, StealthCoder runs invisibly during the live OA as a safety net. Read this first so you don't need it.
The problem
packed has four rows and 4k columns. Every consecutive four-column block is one 4 by 4 logical grid containing the strings 1 through 16, except that exactly one value is replaced by ?. Fill every missing value, sort the logical grids by that numeric value ascending, and return the grids packed side by side in the new order. Function fillAndSortGrids(packed: String[][]) → String[][] Examples Example 1 packed = [["1","2","3","4","?","2","3","4"],["5","6","7","8","5","6","7","8"],["9","10","11","12","9","10","11","12"],["13","14","15","?","13","14","15","16"]] return = [["1","2","3","4","1","2","3","4"],["5","6","7","8","5","6","7","8"],["9","10","11","12","9","10","11","12"],["13","14","15","16","13","14","15","16"]] The filled grids are reordered by missing value. Example 2 packed = [["1","2","3","4"],["5","6","?","8"],["9","10","11","12"],["13","14","15","16"]] return = [["1","2","3","4"],["5","6","7","8"],["9","10","11","12"],["13","14","15","16"]] A single logical grid is filled without movement. Constraints 1 <= k <= 1000 packed.length == 4 and packed[r].length == 4k.
Reported by candidates. Source: FastPrep
Pattern and pitfall
The trick is to treat each four-column block as its own grid. Loop k times, slice columns 4i to 4i+3 across the four rows, and find the one cell equal to "?". Sum 1 through 16 is 136, so the missing value is 136 minus the sum of the other 15 numbers. Replace the "?" with that value. Store each grid with its missing value as the sort key, then sort ascending by that integer, not as a string. String sorting puts "10" before "2" and quietly breaks your output. After sorting, write the grids back side by side into four output rows. The other pitfall is sorting before filling, when the key doesn't exist yet. Complexity is O(k log k) for the sort plus O(16k) for scanning, trivial for k up to 1000. If the index math blanks you mid-assessment, StealthCoder is the hedge that reads the problem and hands you the slicing.
Drill it cold or hedge it with StealthCoder. Either way, don't walk into the OA hoping you remember the trick.
You can drill Fill and Sort Packed Missing-Number Grids 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 ZipRecruiter's OA.
ZipRecruiter 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.
Fill and Sort Packed Missing-Number Grids FAQ
What's the trick in Fill and Sort Packed Missing-Number Grids?+
Each grid holds 1 through 16 with one "?", so the missing value is 136 minus the sum of the other numbers. Use that value as the sort key. Then rebuild the packed output by placing the sorted grids side by side across four rows.
What do I sort by exactly?+
Sort by the missing value you computed for each grid, as an integer, ascending. Don't compare the strings. Lexicographic order would place "10" before "2" and give wrong answers on larger inputs with many grids.
How hard is this ZipRecruiter question really?+
Easy to medium. The algorithm is simple, but the packed layout makes off-by-one errors likely. Most failed attempts come from slicing columns wrong or sorting before filling, not from missing a hard concept.
Do I need to worry about performance with k up to 1000?+
No. That's at most 1000 grids of 16 cells each. Scanning every cell is linear, and sorting 1000 keys is cheap. Any straightforward implementation passes comfortably, so focus on correctness rather than optimization.
How do I prepare in 48 hours?+
Practice slicing a 2D array into fixed-width blocks, computing a key per block, sorting objects by that key, and writing them back. Test with Example 1 by hand, including the case where two grids share the same missing value, to check your ordering.