1
2
3
4
5
6
7
8
9
10
11
12
13
|
Input: nums = [1,0,2,0,3]
Output: 2
Explanation:
The only possible valid selections are the following:
* Choose `curr = 3`, and a movement direction to the left.
* `[1,0,2,**_0_** ,3] -> [1,0,2,0,**_3_**] -> [1,0,2,**_0_** ,2] -> [1,0,**_2_** ,0,2] -> [1,0,1,**_0_** ,2] -> [1,0,1,0,**_3_**] -> [1,0,1,**_0_** ,2] -> [1,0,**_1_** ,0,2] -> [1,0,0,**_0_** ,2] -> [1,0,0,0,**_3_**] -> [1,0,0,**_0_** ,1] -> [1,0,**_0_** ,0,1] -> [1,**_0_** ,0,0,1] -> [**_1_** ,0,0,0,1] -> [0,**_0_** ,0,0,1] -> [0,0,**_0_** ,0,1] -> [0,0,0,**_0_** ,1] -> [0,0,0,0,**_1_**] -> [0,0,0,0,0]`.
* Choose `curr = 3`, and a movement direction to the right.
* `[1,0,2,**_0_** ,3] -> [1,0,2,0,**_3_**] -> [1,0,2,**_0_** ,2] -> [1,0,**_2_** ,0,2] -> [1,0,1,**_0_** ,2] -> [1,0,1,0,**_2_**] -> [1,0,1,**_0_** ,1] -> [1,0,**_1_** ,0,1] -> [1,0,0,**_0_** ,1] -> [1,0,0,0,**_1_**] -> [1,0,0,**_0_** ,0] -> [1,0,**_0_** ,0,0] -> [1,**_0_** ,0,0,0] -> [**_1_** ,0,0,0,0] -> [0,0,0,0,0].`
|