Split Array With Same Average
Real-world version: Splitting the Tray Into Two Equal AveragesThe statement here is our own: the same inputs, outputs and technique.
A tray holds the weights weights. Put every weight into one of two bins, and neither bin may end up empty.
Return true when some way of doing that leaves the two bins with the same average weight.
Examples
Example 1
- Input
- weights = [1, 2, 3]
- Output
- true
Putting the 2 in one bin and the 1 and the 3 in the other gives both bins an average of 2.
Example 2
- Input
- weights = [1, 2, 4]
- Output
- false
The tray totals 7 across three weights. A bin of one weight would have to hold seven thirds and a bin of two would have to total fourteen thirds, and neither is whole.
Example 3
- Input
- weights = [5, 5, 5, 5, 5]
- Output
- true
Every weight is the same, so any split at all leaves both bins on that average.
Constraints
- 1 <= weights.length <= 30
- 0 <= weights[i] <= 10^4
The signature
The editor starts with this. It matches the parent problem's shape, so a solution that works here works on a standard judge unchanged.
def split_array_same_average(weights: list[int]) -> bool:public boolean splitArraySameAverage(int[] weights)Checking your plan…
How this problem was checked
- Passed: Reference solution run against 15 test cases: 15 passed
- Passed: 3 worked examples confirmed by running the code
- Passed: 0 eight-word sequences shared with the parent problem's text
- Passed: Agrees with an independent brute-force solution on random inputs
- Passed: Test set shown to catch deliberately broken solutions
- Passed: Reviewed by a separate quality pass
- Passed: Function arity matches the parent problem's
More on the same topics
- Partition Array Into Two Arrays to Minimize Sum DifferenceReal-world version: Balanced Pontoon BallastHard
- Maximize Score After N OperationsReal-world version: Retiring Blades In Paired SessionsHard
- Maximum Score Words Formed by LettersReal-world version: Best Tile Rack PlayHard
- Stickers to Spell WordReal-world version: Cutting Letters Out of StencilsHard