Problems
June 1, 2023
Shortest path in binary matrix
We will start BFS from the top left corner of the matrix till we reach the bottom right. Then we will return the shortest path length.
Time complexity: O(n)
Space complexity:...
May 28, 2023
Number of substrings containing all three characters
We can use a sliding window to solve the problem. We will use a variable count
to store the number of substrings containing all three characters. Then we will iterate over the string and...
May 28, 2023
Vowels of all substrings
We can use bottom-up dynamic programming to solve the problem. We will use a variable vowels
to store the number of vowels in the string. Then we will iterate over the string and update...
May 27, 2023
Stone game II
We can use top-down dynamic programming to solve the problem. First we will calculate the suffix sum of the piles. Then we will use two pointers i
and m
to iterate over the...
May 27, 2023
Stone game III
We can use top-down dynamic programming to solve the problem. We will use two pointers i
and m
to iterate over the piles and the number of stones that can be taken...
May 27, 2023
Univalued binary tree
We can use depth-first search to solve the problem. We will use a variable val
to store the value of the root node. Then we will recursively check if the value of the current node is...
May 24, 2023
Left and right sum differences
We will iterate over the array and compute the sum of the left and right subarrays as we iterate through. Then we will compute the difference between the sums and append it to our result. Finally we...
ReadMay 24, 2023
Count vowel strings in ranges
We construct alambdaboolean functionvowelsto assess whether the word qualifies. Then we map the words using this function. Then we construct the prefix sum of the mapped words. Finally, we return the...
ReadMay 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...
ReadMay 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