Skip to the code
cf.
+25 XP

#25 Valid Seating Chart

medium

An event app lets organizers assign guests from table groups 1 to n to an n x n seating chart, grid. A 0 means the seat is empty.

The chart is valid if no row and no column has the same non-zero group number twice. Write validSeatingChart(grid) that returns true if the chart is valid and false otherwise.

Example 1

Input: grid = [[1,2,0],[0,3,1],[2,0,3]]
Output: true

Every row and every column has different non-zero numbers.

Example 2

Input: grid = [[1,2],[1,0]]
Output: false

Column 0 has group 1 twice.

Constraints

  • 1 <= n <= 100
  • 0 <= grid[r][c] <= n
Saved in this browser

Run tries your code on the examples. Submit runs every test, including hidden edge cases, and solves the problem when they all pass.

Ctrl + Enter runs, Ctrl + Shift + Enter submits (⌘ on a Mac).