https://ide.geeksforgeeks.org/FNitKtYs8x----what’s the error in my code please help me in correcting it as one test case is showing correct but not passing
Kth element from last in linked list problem
in your if condition
if (k < 0 || k > this.size - 1) {
throw new Exception(“Invalid value of k”);
}
k can’t be this.size, but according to problem statement when k = this.size, it should return first element.
change condition to k>this.size here.
Thanks