Maximum Students Taking Exam

Given an m * n matrix seats that represents the seat distribution in a classroom. If a seat is broken, it is denoted by the '#' character; otherwise, it is denoted by the '.' character.

Students can see the answers of those sitting next to the left, right, upper left, and upper right, but they cannot see the answers of the student sitting directly in front of or behind them.

Return the maximum number of students that can take the exam together without any cheating being possible.

Students must be placed only in seats in good condition.

Example 1
# . # # . #
. # # # # .
# . # # . #
Inputseats = [["#",".","#","#",".","#"],[".","#","#","#","#","."],["#",".","#","#",".","#"]]
Output4
Teacher can place 4 students in available seats so they do not cheat on the exam.
Example 2
. #
# #
# .
# #
. #
Inputseats = [[".","#"],["#","#"],["#","."],["#","#"],[".","#"]]
Output3
All students can be placed in available seats.

Constraints

  • seats contains only characters '.' and '#'.
  • m == seats.length
  • n == seats[i].length
  • 1 <= m <= 8
  • 1 <= n <= 8

Asked at 3 companies

</>

Your Solution

(Ctrl/Cmd + Enter)

Switching Language

Loading template...

Loading...

Sign in to save your progress

AI code evaluation

Get a correctness verdict, missed edge cases, and complexity analysis of your solution.

Sign in to evaluate