clear the code by less space complex o(n)
hald done