Tap here to switch tabs
Problem
Submissions

Problem: Number of Valid Move Combinations On Chessboard

med
30 min
Try to solve the Number of Valid Move Combinations On Chessboard problem.

Statement

There is an 8imes88 imes 8 chessboard with nn pieces placed on it. You are given two arrays: an array of strings pieces and a 22D integer array positions, each of length n, where pieces[i] represents the type of the ii-th piece and positions[i] = [r_i, c_i] represents its starting square using 11 based indexing.

Each piece can be one of three types:

  • A "rook" can move in any of the 44 horizontal or vertical directions.

  • A "queen" can move in any of the 88 horizontal, vertical, or diagonal directions.

  • A "bishop" can move in any of the 44 diagonal directions.

Every piece independently selects a destination square and travels toward it along a straight line at a speed of 11 square per unit time. A piece may also choose to stay on its starting square. All pieces begin moving simultaneously at time t=0t = 0. When a piece reaches its chosen destination, it stops and stays on that square for all subsequent moments.

A move combination is considered valid if at no time t≥0t \geq 0 do two pieces occupy the same square.

Return the total number of valid move combinations.

Constraints:

  • n ==== pieces.length

  • n ==== positions.length

  • 1≤1 \leq n ≤4\leq 4

  • pieces only contains the strings "rook", "queen", and "bishop".

  • There will be at most 11 queen on the chessboard.

  • 1≤ri,ci≤81 \leq r_i, c_i \leq 8

  • Each positions[i] is distinct.

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Number of Valid Move Combinations On Chessboard

med
30 min
Try to solve the Number of Valid Move Combinations On Chessboard problem.

Statement

There is an 8imes88 imes 8 chessboard with nn pieces placed on it. You are given two arrays: an array of strings pieces and a 22D integer array positions, each of length n, where pieces[i] represents the type of the ii-th piece and positions[i] = [r_i, c_i] represents its starting square using 11 based indexing.

Each piece can be one of three types:

  • A "rook" can move in any of the 44 horizontal or vertical directions.

  • A "queen" can move in any of the 88 horizontal, vertical, or diagonal directions.

  • A "bishop" can move in any of the 44 diagonal directions.

Every piece independently selects a destination square and travels toward it along a straight line at a speed of 11 square per unit time. A piece may also choose to stay on its starting square. All pieces begin moving simultaneously at time t=0t = 0. When a piece reaches its chosen destination, it stops and stays on that square for all subsequent moments.

A move combination is considered valid if at no time t≥0t \geq 0 do two pieces occupy the same square.

Return the total number of valid move combinations.

Constraints:

  • n ==== pieces.length

  • n ==== positions.length

  • 1≤1 \leq n ≤4\leq 4

  • pieces only contains the strings "rook", "queen", and "bishop".

  • There will be at most 11 queen on the chessboard.

  • 1≤ri,ci≤81 \leq r_i, c_i \leq 8

  • Each positions[i] is distinct.