Problems
November 4, 2022
Encode and decode tinyurl
We will use two hashmaps, one for storing the code and another for storing the url. The we will create a helper function to get a random string of length 6. We will use this function to generate the...
ReadNovember 4, 2022
Maximum score from removing stones
We will sort 3 numbers and remove 1 stone from the largest 2 numbers until they all become 0. The number of stones removed is the maximum score.
Time complexity: O(n)
, sorting 3...
November 4, 2022
Reverse vowels of a string
We will iterate over the string, and if the character is a vowel, we will add it to a stack. Then we will iterate over the string again, and if the character is a vowel, we will pop the stack and add...
ReadNovember 4, 2022
Partition array into three parts with equal sum
We will calculate the sum of the array. If the sum is not divisible by 3, we return False
. Otherwise, we will iterate over the array and check if the sum of the current subarray is equal...
November 4, 2022
Maximum profit in job scheduling
We will sort the jobs by their end time. Then we will iterate over the jobs, and for each job, we will find the first job that does not overlap with the current job. We will then take the maximum of...
ReadNovember 3, 2022
Smallest good base
First we will convert the string to a integer. Then we calculate the maximum number of digits that the base can have. We will iterate from the maximum number of digits to 2. For each number of...
ReadNovember 3, 2022
Longest palindrome by concatenating two letter words
We can use a hashmap to store the frequency of each word. Then we can iterate over the words and check if the reverse of the word is present in the hashmap. If it is, we add the frequency of the word...
ReadNovember 2, 2022
Count items matching a rule
We will iterate over the items and check if the rule matches. If it does, we increment the count.
Time complexity: O(n)
Space complexity: O(1)
November 2, 2022
Intersection of two arrays
We can use 2 sets to store the elements of each array. Then we can iterate over the elements of the first set and check if it is present in the second set. If it is, we add it to the result. Time...
ReadNovember 2, 2022
Largest 3 same digit number in string
We will start from 9 till 0 and try to find the largest 3 same digit number in the string. If we find it, we return it. Otherwise, we return empty string.
Time complexity: O(n)
Space...