Pattern 3: Fast and Slow pointersThe Fast and Slow pointer approach, also known as the Hare & Tortoise algorithm, is a pointer algorithm that uses two pointers which move through the array (or sequence/linked list) at different speeds. This approach is quite useful when dealing with cyclic linked lists or arrays.
By moving at different speeds (say, in a cyclic linked list), the algorithm proves that the two pointers are bound to meet. The fast pointer should catch the slow pointer once both the pointers are in a cyclic loop.
How To Identify- The problem will deal with a loop in a linked list or array
- When you need to know the position of a certain element or the overall length of the linked list
Questions- Linked List Cycle (easy)
- Palindrome Linked List (medium)
- Cycle in a Circular Array (hard)
Best DSA RESOURCES: https://topmate.io/coding/886874
ENJOY LEARNING 👍👍