Problems
November 5, 2022
Counting words with a given prefix
We will iterate over the words and count the number of words that start with the given prefix.
Time Complexity: O(n)
Space Complexity: O(1)
November 5, 2022
The k strongest values in an array
We will calture the median of the array, and then use two pointers to find the k strongest values.
Time Complexity: O(nlogn)
Space Complexity: O(1)
November 5, 2022
Next greater element II
We will iterate over the array, and push the index of the current element to the stack. If the current element is greater than the element at the top of the stack, we will pop the top of the stack,...
ReadNovember 5, 2022
Word pattern
We will split the string to words. If the numbers of words does not match the numbers of letters in the pattern, we return false. Then we iterate over each letter in the pattern, check the position...
ReadNovember 5, 2022
Sum of beauty of all substrings
We will follow the problem statement, and solve the problem with a brute force approach.
Time Complexity: O(n^2)
Space Complexity: O(n)
November 5, 2022
Majority element
We can count all element in the array, and return the element that has the most count.
Time Complexity: O(n)
Space Complexity: O(n)
November 5, 2022
Find all numbers disappeared in an array
We will iterate over the array, and mark the element at the index of the current element as negative. Then we will iterate over the array again, and add the index of the positive element to the...
ReadNovember 5, 2022
Maximum number of balloons
We will count all the characters, then we will return the minimum of the count of b
, a
, l
, o
, and n
, as the number of l
...
November 5, 2022
Merge in between linked lists
We will use two pointers to find the nodes before and after the merge, and then merge the two linked lists.
Time Complexity: O(n)
Space Complexity: O(1)
November 5, 2022
Find pivot index
We will iterate over the array, and calculate the sum of the left and right side of the current index. If the sum of the left side is equal to the sum of the right side, we will return the current...
Read