LeetCode solutions in Go.
- 1. Two Sum: solution
- Difficulty: Easy
- Category: Array
- Notes: use hash map to instantly check for difference value
- Tutorial: NeetCode , Kevin Naughton Jr., Nick White
- Asked By: Facebook, Google, Amazon, Bloomberg
- 2. Add Two Numbers: solution
- Difficulty: Medium
- Category: Linked List
- 3. Longest Substring Without Repeating Characters: solution
- Difficulty: Medium
- Category: String
- 7. Reverse Integer: solution
- Difficulty: Easy
- 9. Palindrome Number: solution
- Difficulty: Easy
- 11. Container With Most Water: solution
- Difficulty: Medium
- Category: Array
- Tutorials NeetCode - Python
- 13. Roman To Integer: solution
- Difficulty: Easy
- Category: String
- 14. Longest Common Prefix: solution
- Difficulty: Easy
- Category: String
- 15. 3Sum: solution
- Difficulty: Medium
- Category: Array, Two Pointers, Sorting
- Tutorial: NeetCode - Python , Nick White - Java
- Notes: sort array, then for each elem find other 2 elems, like in two sum 2 problem; sort input, for each first element, find next two where -a = b+c, if a=prevA, skip a, if b=prevB skip b to elim duplicates; to find b,c use two pointers, left/right on remaining list;
- 17. Letter Combinations of a Phone Number: solution
- Difficulty: Medium
- Category: String
- 20. Valid Parentheses: solution
- Difficulty: Easy
- Category: String
- Tutorial: NeetCode - Python , Nick White - Java
- Note: push opening brace on stack, pop if matching close brace, at end if stack empty, return true;
- 21. Merge Two Sorted Lists: solution
- Difficulty: Easy
- Category: Linked List
- Notes: insert each node from one list into the other
- Tutorial: NeetCode - Python
- Asked By: Microsoft
- 33. Search in Rotated Sorted Array: solution
- Difficulty: Medium
- Category: Array, Binary search
- Notes: at most two sorted halfs, mid will be apart of left sorted or right sorted, if target is in range of sorted portion then search it, otherwise search other half
- Tutorial: NeetCode - Python , Nick White - Java
- 35. Search Insert Position: solution
- Difficulty: Easy
- Category: Array, Binary search
- Notes: use binary search, to find mid val, check if its match return mid, else return left pointer.
- Tutorial: NeetCode - Python
- 48. Rotate Image: solution
- Difficulty: Medium
- Category: String, Matrix
- 49. Group Anagrams: solution
- Difficulty: Medium
- Category: String, Sorting, Hash Table
- Tutorial: NeetCode - Python , Kevin Naughton Jr. - Java
- Note: create hash table - key will be a frequency in str, then compare and add to result; for each of 26 chars, use count of each char in each word as tuple for key in dict, value is the list of anagrams;
- Asked By: Amazonm Google, Uber, Facebook, Microsoft, Apple
- 53. Maximum Subarray: solution
- Difficulty: Easy
- Category: Arrays
- Notes: pattern: prev subarray can't be negative, dynamic programming: compute max sum for each prefix, sliding window
- Tutorial: NeetCode
- Asked By: Amazon
- 55. Jump Game: solution
- Difficulty: Medium
- Category: Dynamic Programming, Arrays
- Notes: visualize the recursive tree, cache solution for O(n) time/mem complexity, iterative is O(1) mem, just iterate backwards to see if element can reach goal node, if yes, then set it equal to goal node, continue;
- Tutorial: NeetCode - Python , Nick White - Java
- 70. Climbing Stairs: solution
- Difficulty: Easy
- Category: Dynamic Programming, Caching - Memoization
- Tutorial: NeetCode , Kevin Naughton Jr.
- Notes: subproblem find (n-1) and (n-2), sum = n;
- Asked By: Google
- 79. Word Search: solution
- Difficulty: Medium
- Category: Matrix
- 91. Decode Ways: solution
- Difficulty: Medium
- Category: String, Dynamic Programming
- Tutorial: NeetCode , Kevin Naughton Jr.
- Asked By: Facebook, Microsoft, Uber, Google, Twitter, Bloomberg
- 94. Binary Tree Inorder Traversal: solution
- Difficulty: Easy
- Category: Tree
- 98. Validate Binary Search Tree: solution
- Difficulty: Medium
- Category: Tree
- 100. Same Tree: solution
- Difficulty: Easy
- Category: Tree
- Notes: dfs: recursively check left and right nodes of trees at the same time; iterative bfs compare each level of both trees
- Tutorial: NeetCode - Python
- 101. Symmetric Tree: solution
- Difficulty: Easy
- Category: Tree
- 104. Maximum Depth of Binary Tree: solution
- Difficulty: Easy
- Category: Tree
- Notes: recursive dfs to find max-depth of subtrees
- Tutorial: NeetCode - Python
- 108. Convert Sorted Array to Binary Search Tree: solution
- Difficulty: Easy
- Category: Array, Binary Tree
- Notes:
- Tutorial: Nick White - Java , Kevin Naughton Jr. - Java
- 121. Best Time to Buy and Sell Stock: solution
- Difficulty: Easy
- Category: Arrays, Dynamic Programming
- Tutorial: NeetCode
- Notes: find local min and search for local max, sliding window;
- 125. Valid Palindrome: solution
- Difficulty: Easy
- Category: String, Two Pointers
- Tutorial: NeetCode
- Notes: find local min and search for local max, sliding window;
- 136. Single Number: solution
- Difficulty: Easy
- Category: Array
- 141. Linked List Cycle: solution
- Difficulty: Easy
- Category: Linked List
- Tutorial: NeetCode - Python , Nick White - Java
- Notes: 1 - dict to remember visited nodes; 2 - two pointers at different speeds, if they meet there is loop
- 144. Binary Tree Preorder Traversal: solution
- Difficulty: Easy
- Category: Tree
- 152. Maximum Product Subarray: solution
- Difficulty: Medium
- Category: Array, Dynamic Programming
- Tutorial: NeetCode - Python , Xavier Elon - Java
- Notes: dp: compute max and max-abs-val for each prefix subarr;
- 153. Find Minimum in Rotated Sorted Array: solution
- Difficulty: Medium
- Category: Array, Binary
- Tutorial: NeetCode - Python , Nick White - Java
- Notes: check if half of array is sorted in order to find pivot, arr is guaranteed to be in at most two sorted subarrays
- 155. Min Stack: solution
- Difficulty: Easy
- Category: Stack
- 160. Intersection of Two Linked Lists: solution
- Difficulty: Easy
- Category: Linked List
- Notes: use hash map of visited nodes, return first intercept node...
- Tutorial: Kevin Naughton Jr. , Nick White
- Asked By: Amazon, Microsoft, Bloomberg, Oracle, Yahoo
- 167. Two Sum II - Input array is sorted: solution
- Difficulty: Easy
- Category: Array
- 169. Majority Element
- not solved yet
- Difficulty: Easy
- Category: Array
- not solved yet
- 189. Rotate Array: solution
- Difficulty: Medium
- Category: Array
- 190. Reverse Bits: solution
- Difficulty: Easy
- Category: Bit Manipulation
- Tutorial: NeetCode
- Notes: reverse each of 32 bits bit by bit
- 191. Number of 1 Bits: solution
- Difficulty: Easy
- Category: Bit Manipulation
- Notes: Hamming weight. mod and div are expensive, to divide use bit shift, instead of mod to get 1's place use bitwise & 1
- Tutorial: NeetCode
- 198. House Robber: solution
- Difficulty: Medium
- Category: Dynamic Programming
- Notes: for each num, get max of prev subarr, or num + prev subarr not including last element, store results of prev, and prev not including last element
- Tutorial: NeetCode - Python , Nick White - Java
- 200. Number of Islands: solution
- Difficulty: Medium
- Category: Matrix, Array
- 206. Reverse Linked List: solution
- Difficulty: Easy
- Category: Linked List
- Notes: iterate through maintaining cur and prev; recursively reverse, return new head of list
- Tutorial: NeetCode - Python , Nick White - Java
- 217. Contains Duplicate: solution
- Difficulty: Easy
- Category: Arrays, Hash Table
- Notes: hashmap to get unique values in array, to check for duplicates easily
- Tutorial: NeetCode - Python
- 226. Invert Binary Tree: solution
- Difficulty: Easy
- Category: Tree
- Notes: recursive dfs to invert subtrees; bfs to invert levels, use collections.deque; iterative dfs is easy with stack if doing pre-order traversal
- Tutorial: NeetCode - Python
- 234. Palindrome Linked List: solution
- Difficulty: Easy
- Category: Linked List
- 235. Lowest Common Ancestor of a Binary Search Tree: solution
- Difficulty: Easy
- Category: Binary Tree
- Notes: compare p, q values to curr node, base case: one is in left, other in right subtree, then curr is lca;
- Tutorial: NeetCode - Python , Nick White - Java
- 238. Product of Array Except Self: solution
- Difficulty: Medium
- Category: Array
- Tutorial: NeetCode - Python , Nick White - Java
- 242. Valid Anagram: solution
- Difficulty: Easy
- Category: String
- Tutorial: NeetCode - Python
- 268. Missing Number: solution
- Difficulty: Easy
- Category: Arrays, Hash Table, Binary
- Notes: 1st - using hashmap, and find absent; 2nd- using xor operator, to find absent; 3rd - calculate sums of array and sub it.
- Tutorial: NeetCode
- 283. Move Zeroes: solution
- Difficulty: Easy
- Category: Array
- 338. Counting Bits: solution
- Difficulty: Easy
- Category: Bit Manipulation, Dynamic Programming
- Tutorial: NeetCode - Python
- 371. Sum of Two Integers: solution
- Difficulty: Medium
- Category: Math, Bit Manipulation
- 383. Ransom Note: solution
- Difficulty: Easy
- Category: String
- 387. First Unique Character in a String: solution
- Difficulty: Easy
- Category: String
- 404. Sum of Left Leaves: solution
- Difficulty: Easy
- Category: Tree
- 543. Diameter of Binary Tree: solution
- Difficulty: Easy
- Category: Tree
- 617. Merge Two Binary Trees: solution
- Difficulty: Easy
- Category: Tree
- 704. Binary Search: solution
- Difficulty: Easy
- Category: Tree, Array
- 724. Find Pivot Index: solution
- Difficulty: Easy
- Category: Array
- 859. Buddy Strings: solution
- Difficulty: Easy
- Category: String
- 912. Sort an Array: solution
- Difficulty: Medium
- Category: Array
- 1089. Duplicate Zeros: solution
- Difficulty: Easy
- Category: Array
- 1108. Defanging an IP Address: solution
- Difficulty: Easy
- Category: String
- 1394. Find Lucky Integer in an Array: solution
- Difficulty: Easy
- Category: Array
- 1480. Running Sum of 1d Array: solution
- Difficulty: Easy
- Category: Array
- 1636. Sort Array by Increasing Frequency: solution
- Difficulty: Easy
- Category: Array, Hash Table
- 1790. Check if One String Swap Can Make Strings Equal: solution
- Difficulty: Easy
- Category: String
- 1925. Count Square Sum Triples: solution
- Difficulty: Easy
- 1929. Concatenation of Array: solution
- Difficulty: Easy
- Category: Array
- 2206. Divide Array Into Equal Pairs: solution
- Difficulty: Easy
- Category: Array, Hash Table
- 2418. Sort the People: solution
- Difficulty: Easy
- Category: Array, Hash Table