You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// We are given a linked list which contains a cycle. Detect that cycle and break it. Print the linked list after removing the cycle.
7
+
8
+
// Input Format
9
+
// The first line contains space separated integers. The integers are such that all the values are distinct but the value start repeating once the cycle gets completed. The list of integers given ends when -1 is input.
10
+
11
+
// Constraints
12
+
// n < 10^5 where n is the length of list without the cycle
13
+
14
+
// Output Format
15
+
// Output single line containing space separated integers representing the list
16
+
17
+
// Sample Input
18
+
// 1 2 3 4 5 2 3 -1
19
+
// Sample Output
20
+
// 1 2 3 4 5
21
+
// Explanation
22
+
// Initially the first five elements are unique but starts repeating from 2. This means there is a link from 5 back to 2. So it represents a cycle. We have to break this cycle and print the list after breaking the cycle.
0 commit comments