Problems
September 13, 2022
UTF-8 validation
We will follow the problem statement and assume everything is correct and move forward. We will use a try-except statement if anything goes wrong and will return false from the except statement....
ReadSeptember 12, 2022
Longest word in dictionary
We will create a trie and insert all the words in our trie. Then we run BFS to get the largest word, as we are only append the word in our BFS queue, when we reach word's end. So, the longest word...
ReadSeptember 12, 2022
Bag of tokens
We will first sort the tokens and take 2 pointers. If the value of the left pointer token is less than our power, we face down the token, so our score increase, we will also keep a running max score....
ReadSeptember 12, 2022
Different ways to add parentheses
We will create a decision tree with all possible options. As it is given only 3 types of operation is possible, we will check whether the current character belongs to any of these, then we calculate...
ReadSeptember 12, 2022
Elimination game
We will recursively eleminate people from beginning to end and then return backword with the same logic until only one person left, then return that.
Time Complexity: O(n)
Space...
September 12, 2022
Sender with largest word count
We will create a count each words of the the messages for each sender. Then we take the sender with the highest number of word count, sort them and then return the largest sender name...
ReadSeptember 11, 2022
Max sum of a pair with equal sum of digits
This problem is very similar to two sum problem. But instead of storing the complement of the number, we will store the sum of digits of the number. When we iterate over the numbers, we will also...
ReadSeptember 11, 2022
Number of restricted paths from first to last node
We will first create an adjacency list from the edge list. Then we run dijkstra's shortest path algorithm to get the shortest distance from first node every other node. Then we run DFS from first...
ReadSeptember 11, 2022
Maximum difference between node and ancestor
We will keep track of both max value of the tree and min value of the tree from root to leaf. When we reach the leaf, we store the difference between these 2 in our result. We will run the same logic...
ReadSeptember 11, 2022
Minimum falling path sum
We will create a helper function that will calculate the minimum path from the starting row and and column. In the helper function we will check the boundary of the column, if it is out of boundary...
Read