DNA Complement Matching
Check whether a DNA strand is its own reverse complement using two pointers from both ends with base-pair matching (A-T, C-G), in O(n) time.
958 published notes across every category.
Check whether a DNA strand is its own reverse complement using two pointers from both ends with base-pair matching (A-T, C-G), in O(n) time.
Check whether one string is a subsequence of another using two pointers in O(n) time and O(1) space.
Understand the two core two pointer patterns — opposite-direction (converging) and same-direction (fast/slow or read/write) — with when to use each in...
Master the fast and slow pointer technique (Floyd’s algorithm): detect cycles, find the middle, and locate the nth node from the end, all in O(n) time...
Classic iterative binary search on a sorted array in O(log n) time, with Python, Java and C++ code and an overflow-safe midpoint.
Recursive binary search on a sorted array in O(log n) time with O(log n) call-stack space, in Python, Java and C++.
Search Insert Position (LeetCode 35): use lower-bound binary search to find where a target is or should be inserted, in O(log n).
Find First and Last Position of a target in a sorted array (LeetCode 34) using two binary searches (lower and upper bound) in O(log n).
Search in Rotated Sorted Array (LeetCode 33): modified binary search that identifies the sorted half each step, in O(log n).
Search in Rotated Sorted Array II (LeetCode 81) with duplicates: binary search that shrinks ambiguous ends, O(log n) average and O(n) worst case.
Find Minimum in Rotated Sorted Array (LeetCode 153): binary search comparing mid with the right end, in O(log n).
Find Peak Element (LeetCode 162): binary search on the slope to find any element greater than its neighbours in O(log n).