Problems


December 14, 2022

Count number of homogenous substrings

We will use a sliding window approach to solve this problem. We will iterate over the string and keep track of the start and end of the current substring. We will increment the end of the substring...

Read

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...

Read

December 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...

Read

December 13, 2022

Detect capital

We can use python's built in fuction to check the conditions. Time complexity: O(1) Space complexity: O(1)

Read

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...

Read

December 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...

Read

December 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....

Read

December 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,...

Read

December 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...

Read

December 12, 2022

Smallest subtree with all the deepest nodes

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
... 18 19 20 21 22 ...