Given a linked list and a number k, reverse every alternate k nodes of the list. Example: List: 1 - 2 - 3 - 4 - 5 - 6 - 7 - 8 - 9 - 10 - null k = 4 Output: 4 - 3 - 2 - 1 - 5 - 6 - 7 - 8 - 10 - 9 - null
Video coming soon!
Subscribe for more updates
Preparing for interviews? IDeserve team is here to help.
Create your profile
Create your profile, and here is what you will get:
1: Interview practice platform.
2: Once you are ready to take the interview, IDeserve team will help you get connected to the best job opportunities.
3: Personalized mentorship from IDeserve team once your interview process has started.
Creation of profile shouldn't take more than 2 minutes.
1. Traverse k nodes forward and set temp to the k+1th node 2. Reverse k nodes traversed in step 1. Here is a post on how to reverse a linked list: Reverse a Linked List 3. Set next of the last node in this k length list to temp. 4. Traverse next k nodes which are to be skipped. 5. Recursively call steps 1-3 for reversing next k nodes.
Support us by whitelisting IDeserve in your ad-blocker.