Problems
October 22, 2022
Destination city
The destination city can not be seen as departure city. So, we will create a set with all departure cities. Then we iterate all destination cities and check if it is in the set. If not, we return...
ReadOctober 21, 2022
Unique email addresses
We will iterate over the emails and split them into the local name and the domain name. We will then remove all the dots from the local name and remove everything after the first plus sign. We will...
ReadOctober 21, 2022
Isomorphic strings
We can iterate over both string at the same time and look for the first occurrence of each character. If the first occurrence of the character in both strings is not the same, then we will return...
ReadOctober 21, 2022
Contains duplicate II
We will use a hashmap to store the last index of each number. For each number, we will check if the difference between the current index and the last index is less than or equal to k. If it is, then...
ReadOctober 20, 2022
Maximum points you can obtain from cards
We will use two pointers to keep track of the maximum points we can obtain. We will start with the first k cards and the last k cards. Then we will move the pointers to the right and left and check...
ReadOctober 20, 2022
Number of valid move combinations on chessboard
We will simulate the solution, using a set to store the positions and then traverse through each possible position with a DFS and backtrack if we don't find a valid position. Time Complexity:...
ReadOctober 19, 2022
Minimum operations to halve array sum
We will compute the half of the sum of the input nums, put all nums into a max heap. Then pull out and cut the current max value by half and add it back to heap, deduct the half of the sum...
ReadOctober 19, 2022
Short encoding of words
We can find similar suffixes by reversing each word and adding it to our trie. Then, we can perform DFS on the tree-like structure to obtain all maximum-length chains; i.e., words that are not...
ReadOctober 19, 2022
Map sum pairs
We will take a trie and a map. The map will store the key and the value. The trie will store the sum of all the values of the keys that start with the current prefix. We will iterate over all the...
ReadOctober 19, 2022
Queries on a permutation with key
We will do the simulation. Fist we will create a list with all the permutation. For each query, we will find the index of the query value in the permutation, then we will move the value to the front...
Read