Login

All Problems

Problem title

Difficulty

Avg time to solve

Relative Sorting

Moderate

25 mins

Roots of the tree having minimum height

Moderate

25 mins

Cycle Detection in a Singly Linked List

Moderate

15 mins

Remove K Corner Elements

Easy

15 mins

Number Pattern 1

Easy

10 mins

Ninja and characters

Easy

15 mins

Compare Versions

Easy

10 mins

Cooking Ninjas

Moderate

25 mins

Covid Vaccination

Moderate

--

Largest Number in Binary Tree

Moderate

36 mins

Problem

Submissions

15

Avg. time to solve

15 min

Success Rate

80%

Problem Statement

```
The first line of each test case contains the elements of the singly linked list separated by a single space and terminated by -1 and hence -1 would never be a list element.
The second line contains the integer position "pos" which represents the position (0-indexed) in the linked list where tail connects to. If "pos" is -1, then there is no cycle in the linked list.
```

```
The only line of output contains 'true' if linked list has a cycle or 'false' otherwise.
You don't have to explicitly print by yourself. It has been taken care of.
```

```
0 <= N <= 10^6
-1 <= pos < N
-10^9 <= data <= 10^9 and data != -1
Where 'N' is the size of the singly linked list, "pos" represents the position (0-indexed) in the linked list where tail connects to and "data" is the Integer data of singly linked list.
Time Limit: 1 sec
```

```
Try to solve this problem in O(N) Time Complexity and O(1) space Complexity
```

```
3 2 0 -4 -1
1
```

```
true
```

```
1 -1
-1
```

```
false
```

```
1 2 -1
1
```

```
true
```

Console

Sample Test Case

Custom Test Case

Download Test Cases

Test Case 1

Test Case 2

Test Case 3

Saving Code...

Full Screen Mode

Change Language

Change Theme

Solution submission not allowed

Save Code

Reset Code