Problems
December 10, 2022
Find the longest substring containing vowels in even counts
We will use a sliding window to solve this problem. We will keep track of the number of occurrences of each vowel in the window. We will then check if the number of occurrences of each vowel is even....
ReadDecember 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...
ReadDecember 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....
ReadDecember 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...
ReadDecember 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...
ReadDecember 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:...
ReadDecember 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...
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...
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...
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