Your question is Split Integer Into Parts. Start with the requirements on the right.
Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.
LogicMonitor may need to distribute an integer number of alert checks across an even number of workers. Given an integer value and a positive even integer parts, return an array of exactly parts integers whose sum is value and whose values are as evenly balanced as possible.
The output must minimize the difference between the largest and smallest parts. When multiple valid arrays exist, return the deterministic arrangement with larger parts first. For negative values, "larger" means numerically greater, so -2 comes before -3.
Implement split_integer(value, parts).
value and positive even integer parts.parts integers.value.def split_integer(value, parts):