Problems
September 5, 2022
Search in rotated sorted array II
To solve this problem we have to follow the folllowing steps: Calculate the mid index. Check if the mid element == target, return True else move to next step. Else if the mid element >= left. If...
ReadSeptember 5, 2022
Basic calculator
We will take a stack. Initially our operation and operand will be 0 and +
append each character to the stack. If the character is numeric, until we reach an operand we will calculate the...
September 5, 2022
Single number II
We will have 2 elements, one will be store all the values that store all the elements that occurs once and two will store all the elements that occurs twice. Then we make sure that the values that is...
ReadSeptember 5, 2022
All ancestors of a node in a directed acyclic graph
First we will create an ancestors adgacency list, where we can get the immediate parent of each node from the edge list. Then we will run DFS from each node, and get the node list of all reachable...
ReadSeptember 5, 2022
Basic calculator II
We will take a stack. Initially our operation and operand will be 0 and +
append each character to the stack. If the character is numeric, until we reach an operand we will calculate the...
September 5, 2022
Restore ip addresses
We will create a decision tree based on the rule that each segment of the ip address can be between 0 and 255. Then we run our DFS to get all possible options and return the result. Time...
ReadSeptember 5, 2022
Count primes
We will use the algorithm Sieve of Eratosthenes to find the number of primes within a range.
Time Complexity: O(nlog(log(n)))
Space Complexity: O(n)
September 5, 2022
Number of enclaves
We will run DFS from every bordering position of the grid and turn the 1's to 0's. Then we will just count the number of position where we still have 1's left, and return that count as result....
ReadSeptember 5, 2022
Sort list
We will use standard merge sort to sort the list, to get the middle node, we will use a fast and slow pointer approach, rest is standard merge sort stuffs.
Time Complexity: O(nlog(n))
...
September 5, 2022
Course schedule IV
We will first create an adjacency list from the prerequisites. Then for each queires, we will start DFS from course 1 to course 2, if we can reach to course 2, then we append true in our result, else...
Read