Problems
August 22, 2022
Minimum deletions to make string balanced
We can count the number of occurance of b
and then reduce the count with an upcoming a
character, also increase the result count on the way. Finally return our result count...
August 22, 2022
Check if a word occurs as a prefix of any word in a sentence
We will split the string with space then iterate over each word to check the prefix, if we find one, we return the position of the word in the sentence, else we return -1. Time Complexity:...
ReadAugust 22, 2022
Power of four
We will devide the number by 4 until it's 1. If in any step, we have any reminder, we will return false, otherwise return true.
Time Complexity: O(log(n))
Space Complexity:...
August 21, 2022
Cousins in binary tree
We will run a BFS in the tree, and will keep track of the parents, if we find a parent, in a level for one node, we will return false, if we find two parent in a row, we return true. If we find the...
ReadAugust 21, 2022
Construct binary tree from preorder and postorder traversal
We know, the first value of preorder traversal is always the root. From than we can determine the the left subtree's preorder and postorder traversal, and right subtree's preorder and postorder...
ReadAugust 21, 2022
Number of good ways to split a string
We will first count the characters in the string. Then we iterate over the string, add this to the set, and remove the occurance from the count. Then if the length of the set is equal to the length...
ReadAugust 21, 2022
Stamping the sequence
We will start from the target, then move backwords towards our source, which is a string of ?
. We will take a sliding window of length M, which is the length of the stamp, check whether...
August 21, 2022
Check if the sentence is pangram
We will count each character and add it to a hashmap. If the number of characters are equal to 26, we return true otherwise return false.
Time Complexity: O(n)
Space Complexity:...
August 20, 2022
Number of pairs of strings with concatenation equal to target
First we will count the number of frequency of each elements of the input. Then iterate over all possible slices of target and multiply by the count and add it to our final result. If some slices are...
ReadAugust 20, 2022
Minimum number of refueling stops
We can be greedy and use a max heap to to count the number of refueling stop. First we will append the target to the stations list, where fuel will be 0. We will assing the startFuel as nextStop as...
Read