Split Array with Equal Averages

M · mediumP · Verified PYQarraysmath

Given an array of N integers, check if it can be split into two non-empty contiguous parts such that both parts have equal averages. Print “true” if possible, “false” otherwise.

Input
4
1 2 3 4
Output
false
For each split point i (1 to n-1): check if leftSum*(n-i) == rightSum*i. If yes for any i, return true.
← Sort Array of 0s, 1s and 2s (Dutch National Flag)Stock Availability Score →
Report an issue with this question