Four-by-Four Boundary Grid
Updated
Problem statement
Fill a 4 x 4 grid with values from 1 through 4. For this exercise, assume every row and every column contains each value exactly once. There are no additional 2 x 2 box constraints.
The values represent heights. Looking along a row or column from an edge, a height is visible only when it is larger than every height before it.
You receive a 4 x 4 matrix clues:
clues[0][c]is the number visible in columncfrom the top.clues[1][r]is the number visible in rowrfrom the right.clues[2][c]is the number visible in columncfrom the bottom.clues[3][r]is the number visible in rowrfrom the left.- A clue of
0adds no requirement. Row indices always run from top to bottom; column indices always run from left to right, including bottom and right clues.
Return the lexicographically smallest valid grid. Compare the values from left to right across the first row, then the second row, and so on; at the first difference, the smaller value wins. If no grid satisfies every nonzero clue, return an empty matrix [].
Function
solveBoundaryGrid(clues: int[][]) → int[][]Examples
Example 1
clues = [[0,0,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,0]]return = [[1,2,3,4],[2,1,4,3],[3,4,1,2],[4,3,2,1]]No boundary imposes a condition. The lexicographically first Latin grid is selected; no 2 x 2 box rule is applied.
Example 2
clues = [[2,2,3,1],[1,3,3,2],[3,2,1,2],[3,1,2,3]]return = [[2,3,1,4],[4,1,3,2],[3,4,2,1],[1,2,4,3]]All four sides constrain the grid. Each boundary entry is checked from its stated viewing direction.
Example 3
clues = [[1,1,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,0]]return = []Both first two columns would have to begin with 4, which repeats 4 in the first row, so no grid exists.
Constraints
clues.length = 4and every row ofclueshas length4.0 <= clues[s][i] <= 4.- Clues may be incomplete or inconsistent.
More Susquehanna International Group (SIG) Online Assessment questions
- Centered Block Placement QueriesOA · Seen Dec 2026
- Catch Fish with Reusable BaitsOA · Seen Nov 2026
- Bold Play to Reach a GoalOA · Seen Nov 2026
- Cats, Truth and Who Has MoreOA · Seen Nov 2026
- Counting Cows by Their LegsOA · Seen Nov 2026
- Enough Muffins for the LineOA · Seen Nov 2026
- Expected Consecutive Pairs Among Chosen NumbersOA · Seen Nov 2026
- Frog Paths Without Long RunsOA · Seen Nov 2026
- Higher Roll, or Lose the SumOA · Seen Nov 2026
- Is a Popular Story Fake?OA · Seen Nov 2026
Similar questions at other companies
- Word SearchBloomberg LP · OA · PHONE SCREEN · ONSITE INTERVIEWBloomberg LP interview questions
- Rat in a Maze: All Simple PathsPeopleStrong · OAPeopleStrong interview questions
- Find a Word Path Moving Right or DownIntuit · OAIntuit interview questions
- Empty ShelfSquarepoint Capital · OASquarepoint Capital interview questions
- Cave AdvantureMeta · OAMeta interview questions
- Optimal Office PlacementRoblox · OARoblox interview questions
- Complete a Sudoku BoardJP Morgan Chase · OAJP Morgan Chase interview questions
- Word SearchAmazon · ONSITE INTERVIEW
- Word SearchMicrosoft · ONSITE INTERVIEWMicrosoft interview questions
- Enumerate Character Paths to a MarkerTesla · ONSITE INTERVIEWTesla interview questions