Kindly check this code for revrse k problem

public void reverse(int k) throws Exception{

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

}
 
}

i first divided list and simultaneously revrsed the list

Hi Ishant

You have asked the doubt in LinkedList - K Append content but asked doubt for K- Reverse problem. Can you clarify which question are you talking about?

hi your logic and code is fine…try solving this question by changing the pointer of nodes,it will reduce the time complexity of your code…your current codes time complexity is O(n^2)…

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.