Problems


May 23, 2023

Sum in a matrix

We will iterate over each row and sort them. Then we iterate over each column and get the maximum value of the column. Finally, we return the sum of the maximum values. Time complexity:...

Read

May 23, 2023

Maximum subsequence score

We can use a heap to store the elements in the array. Then, we can pop the elements from the heap and add them to the result. We will also keep track of the sum of the elements in the heap. If the...

Read

May 22, 2023

Split a circular linked list

We can use a slow and fast pointer to find the middle of the linked list. Then, we can set the next pointer of the last node to None to split the linked list into two. We can then return...

Read

May 22, 2023

Find three consecutive integers that sum to a given number

We will check whether the number is divisible by 3. If it is, we can return the three consecutive numbers. Otherwise, we will return empty arry. Time complexity: O(1) Space...

Read

May 21, 2023

Kth largest sum in a binary tree

We will traverse the whole tree with BFS and store each levels sum in a list. Then, we will use a heap to get the k-th largest sum. We will also check if the tree doesn't have enough...

Read

May 20, 2023

Maximum profit from trading stocks

This is a classic 0-1 knapsack problem. We can use dynamic programming to solve this problem. We can iterate through the prices array and calculate the maximum profit for each day. The maximum profit...

Read

May 20, 2023

K-th smallest prime fraction

We can use a heap to store the fractions. We can start with the fraction 1/n and add the next smallest fraction to the heap. We can repeat this process until we have added k...

Read

May 19, 2023

The kth factor of n

We can iterate through the numbers from 1 to n and check if the number is a factor of n. If it is, we decrement k by 1. If k is 0, we return the number. Time complexity: O(n) where n...

Read

May 19, 2023

Check if word equals summation of two words

We can convert the words to integers and check if the sum of the first two integers equals the third integer. Time complexity: O(n) where n is the length of the longest word. Space...

Read

May 18, 2023

Number of adjacent elements with the same color

We can use a hashmap to store the indices of each color. Then, we can iterate through the array and check if the adjacent elements have the same color. Time complexity: O(n) where n...

Read
1 2 3 4 5 ...