Search
⌘K

Leetcode 782. Transform to Chessboard

Given an n×n binary grid where you may swap any two rows or any two columns, determine whether you can reorder rows/columns to form an alternating "chessboard" pattern and if so return the minimum number of swaps, otherwise return -1. The core challenge is to verify feasibility from the row/column pattern constraints (only two complementary row types and two complementary column types with correct counts) and compute the minimal row-swaps and column-swaps needed to achieve an alternating arrangement.

Asked at:

Amazon

Amazon


Question Timeline

See when this question was last asked and where, including any notes left by other candidates.

Late August, 2024

Amazon

Amazon

Intern

Given two strings 'start' and 'end' consisting only of X, L, R characters, determine if it's possible to transform 'start' into 'end' using only two operations: swap XL -> LX and swap RX -> XR

Comments

Your account is free and you can post anonymously if you choose.