you will create a 2D array in which each cell contains a pair (L, R) that denotes a domino omitted by a certain position
The initial position indicated by pressing (left, right) by each domino:
1 2 3 4 5 6 7 8 <0, 2> <1, 1> <2, 0> <0, 0> <0, 1> <1, 0> <0, 0> <2, 0>
With this, you do not minimize the array by taking a step that will reduce your array to <0, 0> pairs. In this case, move 1 to R, 3 to L, or 8 to L.
1 to R New Array:
1 2 3 4 5 6 7 8 <0, 0> <0, 0> <0, 0> <0, 0> <0, 1> <1, 0> <0, 0> <2, 0>
We only have 1 Move left, to 8 to L, so New Array:
1 2 3 4 5 6 7 8 <0, 0> <0, 0> <0, 0> <0, 0> <0, 0> <0, 0> <0, 0> <0, 0>
Providing a 2D array:
1 2 3 4 5 6 7 8 <0, 0> <0, 0> <0, 0> <0, 0> <0, 1> <1, 0> <0, 0> <2, 0> // initial <0, 0> <0, 0> <0, 0> <0, 0> <0, 1> <1, 0> <0, 0> <2, 0> // pushed 1 to R <0, 0> <0, 0> <0, 0> <0, 0> <0, 0> <0, 0> <0, 0> <0, 0> // pushed 8 to L
Since all cells are now & lt 0, 0>, we are sure that all dominoes have fallen and no one has stopped.