Hi, I tried to optimise the solution by reducing the number of while loops to one.
However, I am getting a run error in test 0. Can you please explain why?
My code -
Node current = this.head;
Node res = null;
int i = 0;
while(current != null){
if( i == k) res = this.head;
current = current.next;
if(res != null) res = res.next;
i++;
}
return res.data;