v2 time O(n) space O(1) Accepted

in v1 there is a bug when k==len+1

could have avoided it with simple testing with brain!!!!!~!!