Move last element to front of a given Linked List | Set 2

Given a singly linked list and an integer K. The task is to append last K elements of the linked list to front.

Examples:

Input: 1 -> 2 -> 3 -> 4 -> 5 -> 6, k = 3
Output : 4 -> 5 -> 6 -> 1 -> 2 -> 3

Input: 1 -> 2 -> 3 -> 4 -> 5 -> 6, k = 7
Output : 6 -> 1 -> 2 -> 3 -> 4 -> 5

Prerequisites: Move last element to front of a given Linked List



Approach: