Problems


December 10, 2022

Maximum product of splitted binary tree

We will calculate the sum of all nodes in the tree and then we will calculate the sum of all nodes in the left and right subtrees. The answer will be the maximum of the product of the sum of the left...

Read

December 9, 2022

Number of pairs of interchangeable rectangles

We will use a hash map to store the number of rectangles with each width and height. Then we will iterate over the hash map and count the number of pairs of rectangles that can be interchanged....

Read

December 9, 2022

Add two polynomials represented as linked lists

We will use the same approach as in the merge two sorted lists problem. We will iterate over both lists and add the coefficients of the nodes with the same power. If the coefficient is zero, we will...

Read

December 9, 2022

Longest substring with at least k repeating characters

The idea is that any characters in the string that do not satisfy the requirement break the string in multiple parts that do not contain these characters, and for each part we should check the...

Read

December 9, 2022

Design hit counter

We will use a queue to store the timestamps of the hits. We will remove the timestamps that are older than 300 seconds. Then we will return the size of the queue. Time complexity:...

Read

December 9, 2022

Maximize the confusion of an exam

We will use a sliding window to solve this problem. The window will be the size of the maximum number of consecutive characters that can be changed. We will count the maximum number of consecutive...

Read

December 8, 2022

Find root of N-ary tree

We will sum up all the node values of the tree, then all the substruct all the children node values. The remaining value is the root node value. Time complexity: O(n) Space...

Read

December 8, 2022

Insert into a sorted circular linked list

We will use a prev pointer to store the previous node. If the current node is greater than the previous node and less than the next node, then we will insert the node between the...

Read

December 8, 2022

Range frequency queries

We can use a hash map to store the frequency of each number. Then we can use a binary search to find the number of numbers that have a frequency greater than or equal to value. Time complexity:...

Read

December 8, 2022

Maximum number of non overlapping subarrays with sum equals target

We can be greedy and use a hash set to store the prefix sum. If the prefix sum minus target is in the hash set, then we will update the result and clear the hash set. We will return the...

Read
... 20 21 22 23 24 ...