Regarding error in reverse k question

public void reverse(int k) throws Exception{

// Write your code here 
int l=0;
int s=k-1;
while(s<this.size){
  Node nl = this.getNodeAt(l);
  Node ns = this.getNodeAt(s);
  int temp = nl.data;
  nl.data=ns.data;
  ns.data=temp;
  l=l+k;
  s=s+k;

}
 
}
is there any problem in the code ...its  not working

Hi Ishant

Your code doesn’t work for the case

8 8
2 6 5 4 9 8 6 1

When the value of k is equal to the length of the linked list, the list should be reversed entirely.

Hey Ishant,
As you are not responding to this thread, I am marking your doubt as Resolved for now. Re-open it if required.

Please mark your doubts as resolved in your course’s “ Ask Doubt ” section, when your doubt is resolved.