#2056
Number of Valid Move Combinations On Chessboard
candidate master · 1505 · lc hard +32 · verified · 49% accepted · 75 likes · top 35%
Description
An 8x8 chessboard holds n pieces (rooks, queens, or bishops) described by arrays pieces and positions. Assign each piece a destination reachable by its standard movement rules (a piece may also stay put). All pieces move simultaneously — one square per second toward their destination. A move combination is invalid if any two pieces occupy the same square at the same moment. Return the total count of valid move combinations. Note: pieces may pass through each other; no two pieces start on the same square.
Example 1:
Input: pieces = ["rook"], positions = [[1,1]]
Output: 15
Explanation: The image above shows the possible squares the piece can move to.
Example 2:
Input: pieces = ["queen"], positions = [[1,1]]
Output: 22
Explanation: The image above shows the possible squares the piece can move to.
Example 3:
Input: pieces = ["bishop"], positions = [[4,3]]
Output: 12
Explanation: The image above shows the possible squares the piece can move to.
Code
1
2
3