<aside>
💡 Beware sometimes the test cases are so extreme even time taken for logging (for debugging purpose) might lead to TLE. Try doing Koko Eating Banana using binary search if you wanna try.
</aside>
Two Pointers
Introduction
There are majorly 4 big categories and many sub categories in it.
- Running from both ends of an array: The first type of problems are, having two pointers at left and right end of array, then moving them to the center while processing something with them.
- Slow & Fast Pointers: This type uses two pointers with different movement speed. Typically they starts from the left end, then the first pointer advances fast and give some feedback to the slow pointer and do some calculation.
- Running from beginning of 2 arrays / Merging 2 arrays: In this category, you will be given 2 arrays or lists, then have to process them with individual pointers.
- Split & Merge of an array / Divide & Conquer: The last one is similiar to previous category but there is one thing is added. First, you need to split the given list into 2 separate lists and then do two pointers approach to merge or unify them. There aren't many tasks here.
Summary
Description: This method uses two pointers to traverse an array or a list from different ends or directions.
Usage: It's particularly useful for ordered data structures, where we can make intelligent decisions based on the position of the pointers.
Problems: 'Pair with Target Sum', 'Remove Duplicates', 'Squaring a Sorted Array'.
Practice
Island (Matrix Traversal)
Introduction
Summary
Description: It involves traversing a matrix to find 'islands' or contiguous groups of elements.
Usage: It's generally used in grid-based problems, especially when we need to group connected elements together.