Two-Pointers
LeetCode 541: Reverse String II
·1 min
LeetCode
Easy
Two-Pointers
String
LeetCode 541 note: in every block of 2k reverse the first k; when fewer than k remain reverse them all, which slicing handles automatically
LeetCode 455: Assign Cookies
·2 mins
LeetCode
Easy
Array
Two-Pointers
Greedy
Sorting
LeetCode 455 note: sort children and cookies, satisfying the least greedy child with the smallest cookie that suffices; each pointer walks once
LeetCode 392: Is Subsequence
·2 mins
LeetCode
Easy
Two-Pointers
String
Dynamic-Programming
LeetCode 392 note: two pointers; the pointer on t always advances, and the one on s advances on a match; bound-check both
LeetCode 350: Intersection of Two Arrays II
·1 min
LeetCode
Easy
Array
Hash-Table
Two-Pointers
Binary-Search
LeetCode 350 note: an intersection keeping multiplicity, where Counter’s & takes the smaller count from each side
LeetCode 349: Intersection of Two Arrays
·1 min
LeetCode
Easy
Array
Hash-Table
Two-Pointers
Binary-Search
LeetCode 349 note: convert both arrays to sets and intersect them
LeetCode 345: Reverse Vowels of a String
·1 min
LeetCode
Easy
Two-Pointers
String
LeetCode 345 note: the same two pointers as LC 917, with the condition switched to “is a vowel” (both cases)
LeetCode 344: Reverse String
·1 min
LeetCode
Easy
Two-Pointers
String
LeetCode 344 note: swap with two pointers and move inward to reverse in place
LeetCode 283: Move Zeroes
·1 min
LeetCode
Easy
Array
Two-Pointers
LeetCode 283 note: the write pointer advances only on non-zero values, swapping with them, which pushes zeros to the back
LeetCode 234: Palindrome Linked List
·2 mins
LeetCode
Easy
Linked-List
Two-Pointers
Stack
Recursion
LeetCode 234 note: find the middle with fast and slow pointers, reverse the second half, and compare from both ends with O(1) extra space
LeetCode 202: Happy Number
·1 min
LeetCode
Easy
Hash-Table
Math
Two-Pointers
Floyds-Cycle-Finding-Algorithm
LeetCode 202 note: repeatedly take the sum of squared digits, which reaches 1 or enters a cycle; detect it with a set of seen numbers or fast and slow pointers
LeetCode 160: Intersection of Two Linked Lists
·2 mins
LeetCode
Easy
Hash-Table
Linked-List
Two-Pointers
LeetCode 160 note: each pointer walks its own list then the other’s; both cover lenA + lenB steps and reach the intersection, or None, together
LeetCode 141: Linked List Cycle
·2 mins
LeetCode
Easy
Hash-Table
Linked-List
Two-Pointers
Floyds-Cycle-Finding-Algorithm
LeetCode 141 note: Floyd’s cycle detection, fast two steps and slow one; with a cycle they must meet, each advancing from its own position