Minimum Domino Removals
Learn this problemProblem statement
A domino is a rectangular tile divided into two square parts. There are between 1 and 6 dots on each of the parts. There is an array A of length 2*N, representing N dominoes. Dominoes are arranged in a line in the order in which they appear in array A. The number of dots on the left and the right parts of the K-th domino are A[2*K] and A[2*K+1], respectively. For example, an array A = [2, 4, 1, 3, 4, 6, 2, 4, 1, 6] represents a sequence of five domino tiles: (2,4), (1,3), (4,6), (2,4), and (1,6).
In a correct domino sequence, each pair of neighboring tiles should have the same number of dots on their adjacent parts. For example, tiles (2, 4) and (4, 6) form a correct domino sequence and tiles (2, 4) and (1, 3) do not. What is the minimum number of domino tiles that must be removed from the sequence so that the remaining tiles form a correct domino sequence? It is not allowed to reorder or rotate the dominoes.
Function
minNumTiles(A: int[]) → intGiven an array A representing a sequence of N domino tiles, returns the minimum number of tiles that must be removed so that the remaining tiles form a correct domino sequence.
🐰 Source note (Jul 17, 2026): Two example arrays were copied incorrectly from the screenshot. The missing domino and the joined final values have been restored, so the inputs now match their listed answers. The judged core task matches the visible source at about 99%.
Examples
Example 1
A = [2, 4, 1, 3, 4, 6, 2, 4, 1, 6]return = 3
Example 2
A = [5, 1, 2, 6, 6, 1, 3, 1, 4, 3, 4, 3, 4, 6, 1, 2, 4, 1, 6, 2]return = 7(2, 6), (6, 1), and (1, 2). These three form a correct sequence, so the other 7 dominoes are removed.Example 3
A = [1, 5, 3, 3, 1, 3]return = 2Constraints
🍇🍇More Microsoft problems
- Maximum Pipeline ThroughputOA · Seen Jul 2026
- Maximum Strong Team SubarrayOA · Seen Jul 2026
- Minimum Cost K-Capable ModelsOA · Seen Jul 2026
- Alphabetically Smallest PalindromeOA · Seen Jul 2026
- Maximum Reward PointsOA · Seen Jul 2026
- Maximum Strength of Every NeuronOA · Seen Jul 2026
- Neural Network Subnetwork StrengthOA · Seen Jul 2026
- XOR MultiplicationOA · Seen Jul 2026