Solved LeetCode program · 853 of 1,000
#1144 · Decrease Elements To Make Array Zigzag
Original English source
Keep a shared numbers holding 9, 6, 1, 6, and 2. Keep a shared count of 5. Keep a shared trial as a list of 5 zeros. Keep a shared cost of 0.
To score with parity (a whole number). For every spot from 0 to count minus 1, set item spot of trial to item spot of numbers. Set cost to 0.
For every spot from 1 to count minus 1.
If spot modulo 2 is parity and item spot of trial is at most item (spot minus 1) of trial, The gap is item (spot minus 1) of trial minus item spot of trial plus 1, add gap to cost, set item (spot minus 1) of trial to item spot of trial minus 1. If spot modulo 2 is not parity and item spot of trial is at least item (spot minus 1) of trial, The gap is item spot of trial minus item (spot minus 1) of trial plus 1, add gap to cost, set item spot of trial to item (spot minus 1) of trial minus 1.
Score with 0. The evencost is cost. Score with 1. The oddcost is cost. The answer is the smaller of evencost and oddcost. Show answer.
Expected stdout
4