Problems
November 10, 2022
Score of parentheses
We will use a stack to keep track of the score of the parentheses. We will then iterate through the string and if the current character is an opening parenthesis, we will push the current score onto...
ReadNovember 10, 2022
Find peak element
We will use binary search to find the peak element. We will then return the index of the peak element.
Time Complexity: O(log(n))
Space Complexity: O(1)
November 10, 2022
Triangle
We will use recursive DFS to solve the problem. We will then iterate through the triangle and for each row, we will iterate through the row and update the current element with the minimum of the two...
ReadNovember 9, 2022
Distribute candies
We will use a set to keep track of the unique types of candies. We will then return the minimum of the length of the set and half the length of the candy array.
Time Complexity: O(n)
...
November 9, 2022
Online stock span
We will use a stack to keep track of the previous prices. We will then iterate over the prices and pop the stack until the top of the stack is greater than the current price. We will then push the...
ReadNovember 8, 2022
Average value of even numbers that are divisible by three
We will iterate over all elements and filter the numbers that are divisible by 2*3=6. Then we will calculate the average of the numbers. If there are no numbers that are divisible by 6, we will...
ReadNovember 8, 2022
Pascals triangle II
We know n level pascals triangle will have n level. We will start with level 1, we put 1 there. Then we will start a loop from level 2 to level n. Then we fill up the whole level with 1. Then we loop...
ReadNovember 8, 2022
Make the string great
We will iterate over the string and push the characters into the stack. If the top of the stack is the same as the current character but in different cases, we will pop the top of the stack....
ReadNovember 8, 2022
Minimum money required before transactions
Pick a transaction to be the very last one you perform. Before you perform this transaction, you want to perform every transaction that raises your cost, ie, every transaction where the cost is more...
ReadNovember 8, 2022
Knight dialer
We will create a DAG to represent the possible moves of the knight. We will then create a 2D array to represent the number of ways to reach a particular node. We will then iterate over the array and...
Read