Skip to content

Latest commit

 

History

History
36 lines (31 loc) · 8.58 KB

README.md

File metadata and controls

36 lines (31 loc) · 8.58 KB

Anthony's Leetcode and Other Practice

Using Python or Java to answer leet code and other problems to prep for tech interviews

# Title Solution Time/Space Complexity Methods/Notes Date Completed
1 Two Sum Java O(N)/O(N) Hashmap to see if seen the target num subtracted by current number -> return value if have May 25, 2024
14 Longest Common Prefix Java Python O(N)/O(M) for both set empty string, iterate through all the strings at once (need 2 for loops), return when i == len(s) or s[i] != strs[0][i] Apirl 04, 2024
21 Merge Two Sorted Lists Java O(N)/O(N) Creating a new linked list and add in required order June 5, 2024
118 Pascal's Triangle Java Python O(N^2)/O(N^2) Dynamic Programming -> every row is a list/array itself -> recursive calling itself to use previous row to calculate current row May 25, 2024
125 Valid Palindrome Java O(N)/O(1) Two pointers, start at each end and compare June 1, 2024
206 Reverse Linked List Java M1: O(N)/O(1)
M2: O(N)/O(N)
M1: Iteratively M2:Recursively June 5, 2024
217 Contains Duplicate Python M1: O(N^2)/O(1)
M2: O(NlogN)/O(logN)
M3: O(N)/O(N)
M1: Brute Force
M2: sort array first, compare adjacent elements
M3: put elements into HashMap -> containsKey then return true, else false
May 25, 2024
242 Valid Anagram Python M1: O(N)/O(N)
M2: O(NlogN)/O(1) but could also be said to be O(N) for space
M1: using Hashmap to count number of each character
M2: sort the string first
May 26, 2024
344 Reverse String Java O(N)/O(1) Two pointers, start at each end and swap characters June 1, 2024
671 Second Minimum Node in a Binary Tree Java O(N)/O(N) DFS -- preorder traversal but custom towards this special kind of tree -> think case by case Apirl 23, 2024
746 Min Cost Climbing Stairs Java O(N)/O(1) DP -> base case first two steps -> loop curr = cost[i] + min(first,second), first = second, second = curr Apirl 20, 2024
# Title Solution Time/Space Complexity Methods/Notes Date Completed
11 Container With Most Water Java O(N)/O(1) two pointers, starting at opposite ends, move smaller pointer after testing area June 5, 2024
33 Search in Rotated Sorted Array Java O(logN)/O(1) binary search June 5, 2024
49 Group Anagrams Python O(N)/O(N)) HashMap of charCount to the words that can make this anagram May 31, 2024
143 Reorder List Java O(N)/O(N) two pointers, one at each end but with linked lists June 5, 2024
347 Top K Frequent Elements Python O(N)/O(N)) Bucket Sort + HashMap and then loop through for highest frequencies May 31, 2024
743 Network Delay Time Python O(NLogN)/O(N)
O(E*logV) in terms of edges & vertex)
Dikjstra's Algorithm using MinHeap + stack to visit all nodes and see shortest path/weight May 20, 2024
912 Sort an Array Java O(NLogN)/O(logN) merge sort May 20, 2024
# Title Solution Time/Space Complexity Methods/Notes Date Completed
2781 Length of the Longest Valid Substring Java O(N * maxlengthofforbidden^2)/O(sum of forbidden words length) Sliding Window + brute Force June 1, 2024
N-Other N. Numerology Python O(limit× N^(1/2))/O(1) Math + optimization of brute force Nov 2, 2024