#805
Split Array With Same Average
international master · 2060 · lc hard +32 · verified · 26.8% accepted · 1,343 likes · top 5%
Description
You are given an integer array nums.
Distribute every element of nums between two non-empty arrays A and B such that average(A) == average(B).
Return true if such a distribution is achievable, and false otherwise.
Recall that for any array arr, average(arr) equals the sum of its elements divided by its length.
Example 1:
Input: nums = [1,2,3,4,5,6,7,8]
Output: true
Explanation: We can split the array into [1,4,5,8] and [2,3,6,7], and both of them have an average of 4.5.
Example 2:
Input: nums = [3,1]
Output: false
Code
1
2
3