Problems


October 4, 2022

Palindrome number

We can convert the number to string, reverse it and then check whether it's palindrome of not. Time Complexity: O(n) Space Complexity: O(n) First of all it the number...

Read

October 4, 2022

Ugly number

If the number is negative, then it's not a ugly number. Then we do exactly what the problem statement says, we divide the number by 2, 3 and 5 until we can't divide it any more with these numbers. If...

Read

October 3, 2022

Minimum time to make rope colorful

For a group of continuous same characters, we need to delete all the group but leave only one character. For each group of continuous same characters, we need cost = sum_cost(group) -...

Read

October 3, 2022

Asteroid collision

We will take a stack and iterate over all the elements. If the element is positive, we append it on the stack. Else we take the number, check the value of the number. If it is equal to the top of the...

Read

October 2, 2022

Minimum difference between highest and lowest of k scores

We will first sort the elements and then loop over all the elements and take the difference between k elements, and keep a running minimum and then return that as result. Time Complexity:...

Read

October 2, 2022

Number of dice rolls with target sum

We will take the brute force method to solve the problem, in every iteration till n, we will take 1 to k elements and add it to our total recursively. Then when we reach the target, we will add it to...

Read

October 2, 2022

Rotate array

This approach is based on the fact that when we rotate the array k times, k%nk elements from the back end of the array come to the front and the rest of the elements from the front shift backwards....

Read

October 2, 2022

Move zeroes

We will take a simple two pointers approach, the left will be the first index. Then we iterate over the array, and every time we find a zero, we change the position of it with the next character...

Read

October 1, 2022

Valid palindrome II

We will take two pointers, one at the beginning and one at the end. Then we start compare, if it doesn't match, then we try to skip the character in the left pointer and character in right pointer...

Read

October 1, 2022

Intersection of two linked lists

We start from both list together, and if we can't find a match, we change the position of the both list, and continue until we find a match and return that. Time Complexity: O(n)...

Read
... 52 53 54 55 56 ...