Proof of correctness of algorithm to determine whether the elements of an array are repeated an equal number of times
No, your algorithm doesn't work.  Consider if the array A is

A = [1 1 1 1 1 2 2 3 3 3 3 3 3].

Then the array B will be

B = [5 5 5 5 5 2 2 6 6 6 6 6 6].

The sum of B will be 65, and the length of B will be 13, so after division, we'll get the number 5.  This is equal to the first element of B, so your algorithm will output "Yes".  Nonetheless, not all elements of B are the same, and the correct answer is "No".  So, your algorithm gives the wrong output on this case.

Nice try, though!  Figuring out how to build B was probably the hardest part of this problem.



How I found this: I couldn't find a counterexample with two distinct numbers, so next I tried with three distinct numbers.  Let $u,v,w$ denote how often each of those numbers appear.  Then the array will have length $u+v+w$, and B will contain the value $u$ repeated $u$ times, the value $v$ repeated $v$ times, and $w$ repeated $w$ times, so the sum of elements of B is $u^2+v^2+w^2$.  We can find a counterexample if we can find a solution over the positive integers to the Diophantine equation

$${u^2 + v^2 + w^2 \over u+v+w} = u$$

such that $v\ne u$ or $w \ne u$.  This is equivalent to

$$u^2 + v^2 + w^2 = u(u+v+w),$$

where $u,v,w$ are positive integers and either $v\ne u$ or $w \ne u$.  I then picked a few small values of $u$ and tried solving this Diophantine equation using Wolfram Alpha.  The first solution I stumbled across was $u=5$, $v=2$, $w=6$, but there are many others as well.  In retrospect I guess I could have simplified further to

$$v^2 + w^2 = uv + uw$$

but I didn't notice and it turned out not to matter.