Solved LeetCode program · 671 of 1,000
#0903 · Valid Permutations for DI Sequence
Original English source
Keep a shared pattern as empty text. Place "DID" into pattern. Keep a shared size of 4. Keep a shared used holding 0, 0, 0, 0, and 0. Keep a shared picks as an empty list of whole numbers. Keep a shared good of 0. Keep a shared total of 0.
To validate. Set good to 1. The last is the last position of pattern.
For every spot from 0 to last.
The belowpick is item spot of picks. The abovepick is item (spot plus 1) of picks. The symbol is character spot of pattern. If symbol is "I" and belowpick is more than abovepick, set good to 0. If symbol is "D" and belowpick is less than abovepick, set good to 0.
To finish. Validate. If good is 1, add 1 to total.
To arrange from spot (a whole number). If spot is at least size, finish.
For every choice from 1 to size.
If item choice of used is 0, set item choice of used to 1, Place choice into picks, Arrange from spot plus 1, remove the last item from picks, set item choice of used to 0.
Arrange from 0. Show total.
Expected stdout
5