Problems


November 25, 2022

Add two numbers II

We can solve the problem by using stack. We will push the values of the two linked lists into two stacks. Then we will pop the values from the two stacks and add them together. If the sum is greater...

Read

November 25, 2022

Find greatest common divisor of array

We can solve the problem by using Euclidean algorithm. We will find the greatest common divisor of the first two numbers in the array. Then we will find the greatest common divisor of the greatest...

Read

November 25, 2022

Swapping nodes in a linked list

We will iterate over the whole list to find the length of the list. Then we get the kth node as the first node and the (length-k+1)th node as the second node. We will swap the values of the two...

Read

November 25, 2022

Sum of subarray minimums

We can solve it by using stack. We can iterate over the array, and for each element, we can check if the stack is empty or the top of the stack is greater than the current element. If the stack is...

Read

November 24, 2022

Complement of base 10 integer

What is the relationship between input and output? input + output = 111....11 in binary format. Is there any corner case? 0 is a corner case expecting 1, output > input. We can solve it by using bit...

Read

November 24, 2022

The employee that worked on the longest task

We will iterate over the logs, and for each log, we will update the start time and end time of the employee. We will also update the longest task time of the employee. After iterating over the logs,...

Read

November 24, 2022

Stone game VII

We can see dynamic programming structure in this problem: each time we take some stones from the left or from the left side, what is rest is always contigious array. So, let us denote by dp(i, j) the...

Read

November 24, 2022

Minimum number of arrows to burst balloons

We can solve it by using greedy algorithm. We can sort the balloons by the end time. We can iterate over the balloons, and for each balloon, we can check if the start time of the balloon is greater...

Read

November 23, 2022

Sliding window median

We will use a sorted list to store the numbers in the sliding window. Then, we will iterate through the list. For each number, we will find the index of the number in the sorted list. Then, we will...

Read

November 23, 2022

Final prices with a special discount in a shop

We will iterate over the prices array. For each price, we will iterate over the prices array again to find the first price that is less than or equal to the current price. If we find the price, we...

Read
... 30 31 32 33 34 ...