FastPrepValidate Rows and Columns
Problems/Validate Rows and Columns

Validate Rows and Columns

WhatNot logoWhatNot● EasyNEW GRADPHONE SCREEN
QuestionFunctionExamplesConstraints

Problem statement

Source note: The report asks for row and column validation of an n-by-n Sudoku-like board. The judged core task matches the description at about 85%; the complete-board value range, uniqueness rule, bounds, and examples are stated explicitly for practice.

You are given a nonempty square integer matrix grid with n rows and n columns. Return true if every row and every column is valid; otherwise return false.

For this exercise, a valid row or column contains every integer from 1 through n exactly once. A value outside that range makes the grid invalid.

The grid is fully filled. Check rows and columns only; there is no subgrid or diagonal requirement.

Function

isValidGrid(grid: int[][]) → boolean

Examples

Example 1

grid = [[1,2],[2,1]]return = true

Every row and column contains 1 and 2 exactly once.

Example 2

grid = [[1,2],[1,2]]return = false

The rows are valid, but each column repeats a value.

Example 3

grid = [[0]]return = false

A one-cell grid must contain 1; 0 is outside its allowed range.

Constraints

  • For this exercise, assume 1 <= n <= 50.
  • grid.length == n and grid[i].length == n.
  • For this exercise, assume -10^9 <= grid[i][j] <= 10^9.

More WhatNot problems

  • User Journey PathsPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
  • User Journey PathsPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
  • Adjacent Pair and Run RemovalPHONE SCREEN · Seen Oct 2026
All WhatNot interview questionsSee WhatNot hiring insights
Saved
public boolean isValidGrid(int[][] grid) {
    // write your code here
}
Checking account…