# Iterative solution using helper function reverse list and sub dividing the list into k smaller lists

• Easy solution using a helper function reverse list, divide the list into smaller lists of size k, call the reverse list function on the sublist, rearrange the pointers and you would reach the solution. A dummy pointer is used to make the implementation easy.
'''
class Solution {

``````public ListNode reverseKGroup(ListNode head, int k) {
ListNode dummy = new ListNode(0);
ListNode start = dummy;

while( tmp!= null){
int c = 1;
while(c<k && tmp!= null){
tmp = tmp.next;
c++;
}
if(tmp!=null){
ListNode newList = tmp.next;
tmp.next = null;
ListNode reversed = reverseList(dummy.next);
ListNode initial = dummy.next;
dummy.next = reversed;
dummy = initial;
dummy.next = newList;
tmp = newList;
}
}
return start.next;
}
ListNode prev = null;
while(tmp != null){
tmp.next = prev;
prev = tmp;
tmp = nextP;
if(tmp != null)
nextP = tmp.next;
}
return prev;
}
``````

}
'''

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.