Leetcode 75
Leetcode 75
n(n+1)/2 - sum(nums)
Expand around center of 1 or 2 chars while outer 2 char in bound and equal for each char in s. Return longest.
for every num if it can be reached up longest with max of longest and num+jump distance. If num cant be reached r
If out of bounds return 0, if end of path return 1, else return dp of down a square + dp of right a square. Use lru_cac
If n ==1, return 1 elif n==2, return 2 else return helper(n-1)+helper(n-2). Store results in a hashtable. OR use fibonci
create array of ans, for every num add the answer to the problem of num before. If 9<num and num before<27 add
Bottomup: create array size of word, for every word in dict check if it matches current string, if so update ith elemen
Max on current house plus DP on position+2 and DP on position+1. If second to end return max of 2. if end return en
Do House Robber but take max between houses - first house and houses - last house
DP map keep track of longest starting at end and if num is less than curr, update DP. Create array add first num, for
Bottomup: Create array size target+1 and set each index to target+1. For each coin check if target can be made in fe
Create set from nums. For each num check if previous num is in set. If not then check for consecutive numbers. This
Use dfs on every point, if 1 and not in visited add an island and run dfs.
count occurance of each num in dictionary. Use priority qeue to pop top k elements by value.
Sort intervals by start time, for each interval check if starts after previous ends, ends after previous, or is encompass
Add newInterval, sort by start value, remove overlapping intervals. Use extra space for answer. Can do in O(N) with
Sort intervals by start time, for each check if previous end is after curr start, If so add 1 to ans then update curr end
Fast pointer advance to N nodes ahead. Advance slow pointer and fast pointer until fast pointer hits null. Then skip
Create new empty list, while both lists add smaller element then add rest of nonempty list.
Divide and conquer using merge 2 sorted lists
Use fast and slow pointer, if equal return cycle, if one pointer null return no cycle
Prev=None, cur=head. While cur: next = cur.next, cur.next=prev, prev=cur, cur=next. Return prev
Use stack to keep track of opening, if closing not top of stack return false. If stack not empty at end return false. Use
Use unique prime for each char in each string. Find product and use as key of hashmap for each group
Create hashmap with all chars from first string and their count, remove them for each occurance in second string if
Dict of freq of chars, keep l, r pointer. Move r constantly, add r char to freq, if freq-l+r+1>k move l otherwise don’t, t
Def function to count palandroms starting from center. Call function on each char in string and take sum of all result
Map for last time each char was used, loop through string and if char used more recently than start of current subst
If not node return True. Else set min and max vals to None and if val is out of min, max, return false otherwise recur
Use dfs to check if each node is the same in both tree. Dfs should take 2 nodes, one from each tree.
Use bfs but don’t update q with children until q is empty. Use separate array to store curr next and nextLevel
If root is none return 0 otherwise return 1+max of recursive call of left and right node.
Create TrieNode class with map children and boolean endWord. Insert each char and add TrieNode if not in children
Create TrieNode class. Add word like Implement Trie. Search if '.' for all children of node call
If q/p of different sides of root return root else move down. If root = p or q return p or q.
Use dfs, if node then check left and right trees if 2 of curr, left or right are targets then curr node is ans, else if one o
Function checks if each tree = subtree recursively. Call sameTree function recursively on all nodes of tree.
while left < right the check if char is alnum in while loop and if chars don’t match return false else change r/l.
Runtime
O(N)
O(N)
O(N^2)
O(N)
O(N)
Log(N)
O(N)
O(log(n))
O(N)
O(N)
O(N)
O(N^2)
O(N)
O(N*M)
O(N)
O(N)
O(len(s)*DictWord)
O(N)
O(N)
O(N^2) / O(nLog(N))
O(Coins*Target)
O(N)
O(N*M)
O(Nlog(k))
O(nLog(n))
O(nLog(n))
O(nLog(n))
O(N)
O(N+M)
O(Nlog(k))
O(N)
O(N)
O(N)
O(N*M)
O(N+M)
O(N)
O(N^2)
O(N)
O(N)
O(N)
O(N)
O(N)
X
Add O(all letters of all words) SearchO(height) for no .
O(N)
O(H)
O(N)
O(T*ST)
O(N)
Question Number Question Name Array Difficulty Completed
Solution Notes Runtime