Problems


October 1, 2022

Intersection of two linked lists

We start from both list together, and if we can't find a match, we change the position of the both list, and continue until we find a match and return that. Time Complexity: O(n)...

Read

October 1, 2022

Merge sorted array

We would love to work through nums1 and nums2 starting at index 0 and going to the end of each array, comparing them element by element, but because the first m elements of nums1 are important, we...

Read

September 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:...

Read

September 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...

Read

September 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...

Read

September 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...

Read

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...

Read

September 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)...

Read

September 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

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...

Read
... 53 54 55 56 57 ...