Codility Demo Test Solution Java