Problems
September 10, 2022
Partition array according to given pivot
We will take 3 list, one for less, one for equal and one for more than the pivot value. Then we iterate over the input list, append the value to the respective list. Finally we combine 3 list, and...
ReadSeptember 10, 2022
Wildcard matching
We will start from the first character from the beginning of 2 sting, if they match, then we move to the next string, if the character is ?
in p, then also we move to the next string. If...
September 9, 2022
Design a food rating system
We will have a hashmap for mapping the food to the cuisines and another hashmap to for the ratings. Whenever we receive a new rating or change rating, we add it to our max heap where we store the...
ReadSeptember 9, 2022
Minimum number of swaps to make the string balanced
We will iterate over the string, for each opening bracket, we increase the left count by 1. For each closing bracket, if the count of left braket is greater than right bracket, then we increse the...
ReadSeptember 9, 2022
Peeking iterator
We will use a current value property in the class to keep track of current value of the iterator. For rest of the functionality we will just relay the behaviour of the original iterator. Time...
ReadSeptember 9, 2022
Remove linked list elements
We will create a dummy node and attach it before our head. Then we will iterate over each node, if the value of the node is equal to our node, we will remove them. Then we will return the next node...
ReadSeptember 9, 2022
The number of weak characters in the game
We will use a max heap with our properties and use the attack as sorting mechanism. Then we loop over our properties, pop the max item from the heap, and then we need to check the current defense,...
ReadSeptember 9, 2022
Tuple with same product
We will first count the product of 2 elements to a hashmap, where the key will be product. Then we iterate over each product, if it is more than 1, then we calculate the number of tuple by...
ReadSeptember 8, 2022
Build an array with stack operations
We will create a stack to match with our target and also create a result list. Then we start a loop from 1 to n and append each number to the stack. If the top of the stack does not match our target,...
ReadSeptember 8, 2022
Combination sum III
We will run DFS towards our decision tree, for building a decision tree, we have 2 options, either we take the number or we skip the number. We will check when the sum of the numbers we took is equal...
Read