Perfect squares solution and time limit exceeded solution