Maximum Students Taking Exam - Problem
Given an m × n matrix seats that represents seat distributions in a classroom. If a seat is broken, it is denoted by '#' character, otherwise it is denoted by '.' character.
Students can see the answers of those sitting next to them on the left, right, upper left and upper right, but they cannot see the answers of students sitting directly in front or behind them.
Return the maximum number of students that can take the exam together without any cheating being possible.
Note: Students must be placed in seats that are in good condition (marked with '.').
Input & Output
Example 1 — Basic Case
$
Input:
seats = [[".","#"],["#","#"],["#","."],["#","#"],[".","#"]]
›
Output:
1
💡 Note:
Only one student can be placed at seats[0][0] or seats[2][1] or seats[4][0] without any cheating possibility
Example 2 — Multiple Students
$
Input:
seats = [[".",".","."],[".",".","."],[".",".","."]]
›
Output:
4
💡 Note:
Students can be placed at (0,0), (0,2), (2,0), (2,2) in a checkerboard pattern to avoid cheating
Example 3 — All Broken Seats
$
Input:
seats = [["#","#"],["#","#"]]
›
Output:
0
💡 Note:
No students can be placed since all seats are broken
Constraints
- 1 ≤ seats.length ≤ 8
- 1 ≤ seats[r].length ≤ 8
- seats[r][c] is either '.' or '#'
Visualization
Tap to expand
Understanding the Visualization
1
Input
Classroom with available (.) and broken (#) seats
2
Constraint
Students can cheat diagonally and sideways
3
Solution
Place maximum students without cheating
Key Takeaway
🎯 Key Insight: Use bitmask DP to efficiently track valid seating arrangements row by row
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code