Solved LeetCode program · 936 of 1,000
#1300 · Sum of Mutated Array Closest to Target
Original English source
The numbers is a list of 4, 9, and 3. The target is 10. The last is the last position of numbers. The highest is item 0 of numbers.
For every spot from 1 to last.
If item spot of numbers is more than highest, set highest to item spot of numbers.
The answer is 0. The best is 1000000.
For every guess from 0 to highest.
The total is 0.
For every spot from 0 to last.
The capped is item spot of numbers. If capped is more than guess, set capped to guess. Increase total by capped.
If spot is last.
The difference is total minus target. If difference is less than 0, set difference to 0 minus difference. If difference is less than best, set best to difference, set answer to guess.
Show answer.
Expected stdout
3