Split Array With Same Average

Hard

Description

Given an integer array nums, return true if nums can be split into two non-empty subsets with equal average value.

Examples

Input:nums = [1,2,3,4,5,6,7,8]
Output:true
Explanation:

[1,4],[2,3,5,6,7,8].

Input:nums = [3,1]
Output:false
Explanation:

The only possible split is [3] and [1], which have averages 3 and 1 respectively. There is no way to split the array into two non-empty parts with equal averages.

Input:nums = [2,4,6,8]
Output:true
Explanation:

Splitting into [2,6] and [4,8] gives both groups the same average of 4.

Constraints

  • 1 ≤ nums.length ≤ 30

Ready to solve this problem?

Practice solo or challenge other developers in a real-time coding battle!