Problems
October 1, 2022
Reverse string
We will take 2 pointers, one at the beginning and one at the end of the string. Then we swap their position and move to the next character. Once these two pointers meet, we stop. Time Complexity:...
ReadOctober 1, 2022
Valid palindrome II
We will take two pointers, one at the beginning and one at the end. Then we start compare, if it doesn't match, then we try to skip the character in the left pointer and character in right pointer...
ReadSeptember 30, 2022
Destroying asteroids
We can sort the arstroids and greedy simulate the process described in the problem statement. If at any point the mass is less that the asteroid, then we return false, otherwise if we can finish...
ReadSeptember 30, 2022
Dota2 senate
We will take 2 queues one for dire and one for radiants which keeps their indexes. We pop from both queue whichever is larger(y) index we will bann that. and append smaller_element (x)+ idx as this...
ReadSeptember 30, 2022
Reveal cards in increasing order
we will first sort the deck in descending order. Then we iterate over each card of the deck and append it to a queue. And before appending, if the queue is not empty, then we pop the card from the...
ReadSeptember 30, 2022
Word break II
We will use backtracking to find all possible word match from our word dictionary and add that to our result array and finally return it.
Time Complexity: O(n^2)
Space Complexity:...
September 29, 2022
Design front middle back queue
We will use 2 queue, both of them will have half of the elements. One queue must not be bigger than 1 element. Every time we add and remove an element, we will balance both the queue. Time...
ReadSeptember 29, 2022
Find the winner of the circular game
We can use a queue and add all the numbers to the queue and then remove every kth element. Then when just one item is left in the queue, we return that item.
Time Complexity: O(n*k)
...
September 28, 2022
Flood fill
We will start from the source row and column and visit all connected position with the same color using DFS and color them with our new color. We will keep a visited set to avoid repetation of the...
ReadSeptember 28, 2022
Product of the last k numbers
We will calculate the prefix product while adding number to the queue. Then while getting the product, we will divive the last item with the last kth item to get the product of last k elements....
Read