Reverse Alternate K Nodes in a Singly Linked List
Given a singly linked list and an integer 'k' reverse every 'k' element.
We'll cover the following
Statement
Given a singly linked list and an integer k
, write a function to reverse every k
element.
- If , then the input list is unchanged.
- If ( is the length of the linked list), then reverse the linked list according to
k
.
Example
Below is an example of an input and output linked list after reversing every elements:
Level up your interview prep. Join Educative to access 80+ hands-on prep courses.