Solution (source code)

= Solution

By <character orthogonality>, the squared multiplicities are the <character inner product> norm of the <restriction of a character>:
$$
\sum_{i=1}^r a_i^2
=\langle\chi\mathbin{\downarrow}_H,\chi\mathbin{\downarrow}_H\rangle_H
=\frac1{|H|}\sum_{h\in H}|\chi(h)|^2.
$$
Since $\chi$ is an <irreducible character>, its norm on $G$ is one, and hence
$$
\sum_i a_i^2
\leq\frac1{|H|}\sum_{g\in G}|\chi(g)|^2
=\frac{|G|}{|H|}=[G:H].
$$
The omitted summands are nonnegative, so the <character restriction norm bound> is an equality precisely when
$$
\boxed{\chi(g)=0\quad\text{for every }g\in G\setminus H.}
$$