Basically round-robin increment or decrement until it's done; it's a valid strategy depending on desired outcome (my approach is weighted, so if one candidate is 0 in original array, it'll never increase (unless all candidates were 0), there's value in that) And with your strategy, you could reduce iterations by doing Math.floor(available / (length - 1)) and increment/decrement as much as possible at a time. Also you can remove isgreater check by burning sign into the correction value
goes into negative if new value is high
Recommendation?
I ran the wrong test, ignore this
Обсуждают сегодня