Minimum Rooks in a Peaceful State (SDE 2, Phone Interview)

Problem Overview

  • Determine the minimum number of rooks left after capturing as many as possible so the board is peaceful (no two share a row or column).
  • Input: n×m grid with 0 for empty and 1 for rook; Output: minimal remaining rook count in a peaceful state.
  • Constraints: 1 ≤ n,m ≤ 1000; a rook can move only to capture if another rook is in its row or column.
  • Context: chessboard setup and movement rules; this Amazon coding interview problem is a common interview question.

Example

Unlock to view complete problem details

and practice with sample input/output

Was this article helpful?

View Test Cases & Run Code requires membership

Input Variables
Execution Result: