Skip to content

Commit 4fe8fda

Browse files
author
Amogh Singhal
authored
Update Interview_Questions.md
1 parent b5d671b commit 4fe8fda

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

Interview_Questions.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1-
## 1. How to find the middle element of a linked list
1+
## 1. How to find the middle element of a linked list in one pass
22
Solution: Start with two pointer `p` and `q`. For every second iteration of `p`, iterate `q`. When `p` reaches the end of the linked list. `q` will be in the middle of the list.
33

4-
## 2. How to find the loop or cycle in a linked list
4+
## 2. How to find the loop or cycle in a linked list in one pass
55
Solution: Start with two pointer `p` and `q`. For every second iteration of `p`, iterate `q`. If `p` and `q` are pointing to the same node, there is a loop or cycle present.
6+
7+
## 3. How to find the `k th` element from a linked list in one pass
8+
Solution: Start with two pointer `p` and `q`. When the `p` pointer reahces upto the `k th` element, increment `q`.When `p` reaches the end of the list. `q` is ponting to the element 'k th' from the end.

0 commit comments

Comments
 (0)