passed all cases, but way too slow. next: optimization