Problems
December 14, 2022
Ugly number III
We will use a binary search approach to solve this problem. We will find the smallest number that is divisible by a
, b
, and c
. We will find the smallest number...
December 13, 2022
Check whether two strings are almost equivalent
We will merge all the characters of the string to a hash set and we will keep on iterating over the characters of the set. Then we count the difference between the characters of the string and the...
ReadDecember 13, 2022
Detect capital
We can use python's built in fuction to check the conditions.
Time complexity: O(1)
Space complexity: O(1)
December 13, 2022
Increasing subsequences
We will use backtracking to get all the subsequence of the array. We will keep on iterating over the array and we will check whether the current element is greater than the last element of the...
ReadDecember 13, 2022
Letter case permutation
We will use backtracking to solve this problem. We will iterate over the string and if we encounter a letter, we will add the lowercase and uppercase version of the letter to the result. If we...
ReadDecember 13, 2022
Moving average from data stream
We will use a queue to store the values. We will keep track of the sum of the values in the queue. We will add the new value to the queue and remove the oldest value from the queue. We will return...
ReadDecember 12, 2022
Average waiting time
We will keep on iterating over the intervals and we will check whether the current interval can be served. If it can be served, we will update the current time to be the maximum of the current time...
ReadDecember 12, 2022
Longest square streak in an array
We will use a greedy approach to solve this problem. We will keep on iterating over the sorted array and we will check whether the square of the number is available in the array. If it is available,...
ReadDecember 12, 2022
Longest univalue path
This problem is very similar to diameter of the tree problem. We will keep on iterating over the nodes of the tree and we will check whether the current node is the root of the longest univalue path....
ReadDecember 12, 2022
Lowest common ancestor of deepest leaves
We will traverse the tree with DFS and it will return the deepest depth of the tree and the lowest common ancestor of the deepest leaves. We will keep on iterating over the nodes of the tree and we...
Read