Problems


November 21, 2022

Maximum sum circular subarray

We will use Kadane's algorithm to find the maximum subarray sum. Then, we will find the minimum subarray sum and subtract it from the total sum of the array. If the total sum is greater than the...

Read

November 21, 2022

Sum of absolute differences in a sorted array

The absolute difference between two numbers a and b is: a - b: When a is greater than or equal to b. b - a: When a is less than or equal to b. These cases overlap when a...

Read

November 21, 2022

Base 7

We will divide the number by 7 and keep track of the remainder. We will add the remainder to the result and multiply the result by 10. We will repeat this process until the number is 0. Time...

Read

November 21, 2022

Number of operations to make network connected

We will create an adjacency list of the graph and then we will traverse the graph using DFS and count the number of connected components. If the number of connected components is greater than 1, then...

Read

November 21, 2022

Total cost to hire k workers

We will sort the workers by their quality and iterate through them. For each worker, we will add their wage to the heap and remove the highest wage if the heap size is greater than k. We...

Read

November 20, 2022

All nodes distance k in binary tree

First we will traverse the tree using DFS and create an adjacency list for each node. Then we will use BFS to find all nodes that are k distance away from the target node. Time...

Read

November 20, 2022

Reverse prefix of word

We will iterate through the word and check if the current character is equal to the first character of the prefix. If it is, we will reverse the prefix and return the word. Time complexity:...

Read

November 20, 2022

Path with maximum probability

We can use Dijkstra's algorithm to find the shortest path from the start node to the end node. We will keep track of the probability of the shortest path from the start node to the current node. Then...

Read

November 20, 2022

Maximum length of pair chain

We will first sort all the pairs by the second element. Then we will iterate over each pair and we will check if the current pair's first element is greater than the previous pair's second element....

Read

November 20, 2022

Find all duplicates in an array

We will count the frequency of each number in the array, and return the numbers that appear twice. Time complexity: O(n) Space complexity: O(n)

Read
... 33 34 35 36 37 ...