All problems
1165HardArrayHash TableMathDynamic ProgrammingBit ManipulationMeet in the MiddleBitmask

Splitting the Tray Into Two Equal Averages

Tracked in this browser only
Write code

Trains the technique from

LeetCode 805Split Array With Same Average

This is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.

Same function shape, different story and different numbers.

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 is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.

Python
def split_array_same_average(weights: list[int]) -> bool:
Java
public boolean splitArraySameAverage(int[] weights)
September 7
Apply