- #0001 TwoSum: HashMap solution
- #0121 Best Time to Buy and Sell Stock: Sliding Window. Find local min and search for local max.
- #0217 Contains Duplicate: HashSet.
- #0053 Maximum Subarray: Previous subarray can't be negative.
- #0015 3Sum: Sort input, then simplify the problem to the 2Sum problem.
- #0152 Maximum Product Subarray: DP. Compute max and min for each prefix subarray.
- #0238 Product of Array Except Self: Prefix & Postfix. Make two passes, first in-order, second in-reverse, to compute products.
- #0153 Find Minimum in Rotated Sorted Array - Binary Search
- #0206 Reverse Linked List: Iterative or Recursive Iterate through maintaining cur and prev; Recursively reverse, return new head of list
- #0141Linked List Cycle: Fast & Slow pointers. Hash Set to remember visited nodes; Fast and slow pointers. The loop exists if they meet;
- #0021 Merge Two Sorted Lists: Insert each node from one list into the other.
- #0019 Remove Nth Node From End Of List: Two Pointers. Two pointers, second has offset of n from the first.
- #0242 Valid Anagram, hashmap to count each char in str1, decrement for str2
- #0003 Longest Substring Without Repeating Characters. Sliding Window, Sliding window with hash set.
- #0020 Valid Parentheses Use stack.
- #424 LongestRepeatingCharacterReplacement use sliding window to optimize.
- #0125 ValidPalindrome
Time complexity of O(N^2). Source code.
- Insertion sort
- Selection sort
- Bubble sort Time complexity of O(N log N). Source code
- Quick sort
- Merge sort