Problems
September 27, 2022
Design circular deque
We can use a deque from the collections in python, and use it as our q. We just need to make sure, we don't overflow the queue as we are given a size.
Time Complexity: O(1)
, for each...
September 27, 2022
Strictly palindromic number
We can convert the number to it's base, and check whether it's a palindromic string or not, and return the result.
Time Complexity: O(n^2)
Space Complexity: O(1)
There...
September 27, 2022
Bulb switcher
Basically, if bulb A has an odd number of factors, then that bulb will be on in the end because each bulb is off at the start. If bulb Ahas an even number of factors, then that bulb will be off in...
ReadSeptember 27, 2022
Flatten nested list iterator
We will iterate over the nested list, and go through each element and add that to a queue. Then when we need to check the next, we can pop the value from the queue. For the hasNext, we can just check...
ReadSeptember 27, 2022
Reverse string II
We will divide the string to a list if characters. Then we take k characters and reverse it. Then we skip another k characters and take the next k characters. So, we are looping over the list with...
ReadSeptember 27, 2022
Push dominoes
Any triplet that reaches the state R.L
remains that state permanently. These changes occur to pairs that are not part of an R.L
, R.
-> RR
an...
September 26, 2022
Satisfiability of equality equations
We make an undirected graph in which the nodes are integers (as lower-case letters) and each edge connects integers that are equal. We use the union-find algorithm to determine the connected graphs....
ReadSeptember 25, 2022
Count nice pairs in an array
The problem statement says nums[i]+rev(nums[j]) == nums[j]+rev(nums[i]) is the defination of nice pairs. This can also be restated as nums[i]-rev(nums[i]) == nums[j]-rev(nums[j]). We will use this...
ReadSeptember 23, 2022
Partition to k equal sum subsets
We can try to split the numbers to k subsets, for that every subsets' sum will be total sum divided by k. It is best to iterate the input from biggest numbers, so that we can cut off bad solution...
ReadSeptember 23, 2022
Concatenation of consecutive binary numbers
We will take a brute force approach to solve the problem. But rather than using bin
function to convert the number to binary, which is prefixed with 0b
, we can use the...