a TLE solution
add a o(n) time solution, accepted