Validate Rows and Columns
Updated
Problem statement
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[][]) → booleanExamples
Example 1
grid = [[1,2],[2,1]]return = trueEvery row and column contains 1 and 2 exactly once.
Example 2
grid = [[1,2],[1,2]]return = falseThe rows are valid, but each column repeats a value.
Example 3
grid = [[0]]return = falseA one-cell grid must contain 1; 0 is outside its allowed range.
Constraints
- For this exercise, assume
1 <= n <= 50. grid.length == nandgrid[i].length == n.- For this exercise, assume
-10^9 <= grid[i][j] <= 10^9.
More WhatNot Phone Screen questions
- Merge Sorted Squares of Two ArraysPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Adjacent Pair and Run RemovalPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- User Journey PathsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- User Journey Paths from a Log StreamPHONE SCREEN · Seen Nov 2026
- Reachable Exits in an Obstacle GridPHONE SCREEN · Seen Oct 2026
- Palindrome with One DeletionPHONE SCREEN · Seen Oct 2026
- Search a 2D MatrixPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
- Attraction Route Without Reusing TrailsPHONE SCREEN · Seen Sep 2026
- Earliest Car for Each PassengerPHONE SCREEN · Seen Sep 2026
- Minimum Stores for a Shopping ListPHONE SCREEN · Seen Sep 2026
Similar questions at other companies
- Unique Pairs in a 2D Matrix Summing to TargetAmazon · PHONE SCREEN
- Validate a Latin-Square MatrixKarat · PHONE SCREENKarat interview questions
- Word Chain Jumps in a GridGoogle · PHONE SCREENGoogle interview questions
- Sparse Plant Infection SimulationOpenAI · PHONE SCREEN · ONSITE INTERVIEWOpenAI interview questions
- Sparse Matrix Addition and MultiplicationPinterest · PHONE SCREENPinterest interview questions
- Sudoku Board ValidationConfluent · PHONE SCREEN · ONSITE INTERVIEWConfluent interview questions
- Sparse Matrix MultiplicationByteDance · PHONE SCREENByteDance interview questions
- Valid SudokuVerkada · PHONE SCREENVerkada interview questions
- Configurable Tic-Tac-Toe GameEliseAI · PHONE SCREEN
- Validate Completed SudokuApple · PHONE SCREENApple interview questions