I am doing a leetcode problem:
https://leetcode.com/problems/split-array-with-same-average/description/
The solutions are all assuming "the average of each partition is the average of the entire array when they are equal", but I cannot figure out why? Does anyone know why the assumption is true?
The solutions is here:
Let's say that original values are $$ x_1, \ldots, x_n, y_1, \ldots, y_k. $$ Then the average of these is $$ A = \frac{1}{n+k}(x_1 + \ldots + x_n + y_1 + \ldots y_k) $$ while the averages of the individual parts are $$ B = \frac{1}{n}(x_1 + \ldots + x_n) C = \frac{1}{k}(y_1 + \ldots + y_k) $$ Now suppose that $B$ and $C$ are equal -- just use the letter $B$ -- then we get that $$ nB = (x_1 + \ldots + x_n), kB= (y_1 + \ldots + y_k) $$ Summing, we get $$ (x_1 + \ldots + x_n) + (y_1 + \ldots + y_k) = nB + kB = (n+k)B $$ so that $$ \frac{1}{n+k}\left[(x_1 + \ldots + x_n) + (y_1 + \ldots + y_k)\right] = B $$ But the left hand side is exactly the overall average $A$. So $A = B$ as required.