1377. Maximum Students Taking Exam

HardBit ManipulationBitmask DPProfile DPGrid

A classroom is given as a grid of rows where '.' marks a usable seat and '#' marks a broken one. A student can copy from the seats immediately left, immediately right, upper-left and upper-right of their own. Seat as many students as possible so that no student can copy from another, and return that maximum number.

Input: A JSON object {"seats": [<row strings of '.' and '#'>]}.

Output: Return the maximum number of students that can be seated.

Examples

Example 1
Input: {"seats":["#.##.#",".####.","#.##.#"]}
Output: 4
Explanation: At most four students can sit without copying.
Example 2
Input: {"seats":[".##",".##",".##"]}
Output: 3
Explanation: Only the first column is usable, seating three students.

Constraints

Asked by

GoogleMicrosoft
Solve this problem in the editor →