Skip to main content

Reverse alternate K nodes in a Linked List

Example 1
Linked List Element :  1  2  3  4  5  6  7  8  9  10
Reverse alternate 3 nodes
Linked List Element :  3  2  1  4  5  6  9  8  7  10

Problem is based on reversing node link not node value. For example.

Reverse alternate K nodes in a Linked List

In case group of alternate nodes are less than k in this case not reverse this group. For example.

Example 2
    Before reverse alternate 4 nodes
    1   2   3   4   5   6   7   8   9  10
    ①  ②   ③  ④  (k = 4)


    Reverse 4 nodes
    4   3   2   1   5   6   7   8   9  10
                    ⤑  ⤑   ⤑   ⤑ Skip k nodes

    4   3   2   1   5   6   7   8   9  10
                                    ①  ②  (k = 4)

                                (2 nodes less than k)  
                                  So it's not reverse   
  

Here given code implementation process.





Comment

Please share your knowledge to improve code and content standard. Also submit your doubts, and test case. We improve by your feedback. We will try to resolve your query as soon as possible.

New Comment