• Courses
  • Tutorials
  • Jobs
  • Practice
  • Contests
January 23, 2024 |580 Views
SDE Sheet - Rotate a Linked List
  Share  2 Likes
Description
Discussion

This video is part of Linked List under GFG SDE Sheet

In this problem, we are given a singly linked list of size N. The task is to left-shift the linked list by k nodes, where k is a given positive integer smaller than or equal to the length of the linked list.

Example :

Input:
N = 5
value[] = {2, 4, 7, 8, 9}
k = 3
Output: 8 9 2 4 7

Explanation:
Rotate 1: 4 -> 7 -> 8 -> 9 -> 2
Rotate 2: 7 -> 8 -> 9 -> 2 -> 4
Rotate 3: 8 -> 9 -> 2 -> 4 -> 7

Try out the problem yourself, before going through the solution. All the best!!!

SDE Sheet: https://www.geeksforgeeks.org/sde-sheet-a-complete-guide-for-sde-preparation/
Problem Link: https://www.geeksforgeeks.org/problems/rotate-a-linked-list/1

Read More