• Courses
  • Tutorials
  • Jobs
  • Practice
  • Contests
September 13, 2023 |220 Views
SDE Sheet - Remove loop in Linked List
  Share   Like
Description
Discussion

This video is part of the Linked List section in the GFG SDE Sheet.

In this video, we are given a linked list of N nodes such that it may contain a loop.

A loop here means that the last node of the link list is connected to the node at position X(1-based index). If the link list does not have any loop, X=0.

Remove the loop from the linked list, if it is present, i.e. unlink the last node which is forming the loop.

Example :

Input:
N = 3
value[] = {1,3,4}
X = 2

Output: 1

Explanation: The link list looks like
1 -> 3 -> 4
         ^     |
         |____|    

A loop is present. If you remove it successfully, the answer will be 1. 

Try it out before watching the implementation of the problem in the video. We recommend watching the video, even if you can solve the problem. You may discover something new. All the best!!!

Do check out:-

Article: https://www.geeksforgeeks.org/detect-and-remove-loop-in-a-Linked-list/
Problem: https://practice.geeksforgeeks.org/problems/remove-loop-in-linked-list/1
SDE Sheet: https://www.geeksforgeeks.org/sde-sheet-a-complete-guide-for-sde-preparation/

Read More