Problems


August 27, 2022

Remove k digits

We will use a monotonic decreasing stack to keep track of the digits. We will remove most significant k digits from the stack and then return the values, if the stack is empty at that point we will...

Read

August 27, 2022

Check if a string contains all binary codes of size k

First we will divide the string to all possible substring of length k. Then add all of them into a hashset. If the length of the hashset is equals to 2^k, then we found all possible number and return...

Read

August 26, 2022

Reordered power of 2

We will count the number of digits in out given input. Then we take all the power of 2 from 1 to 32 bit integers, compare the digits of them, if any one of it matches with our given input, we return...

Read

August 26, 2022

Minimum number of flips to make the binary string alternating

We will take the string, and start comparing with first character as 0, and count the number of flips required. If we take first character as 1, the number of flips will be length of the string minus...

Read

August 25, 2022

Ransom note

We will count each character from magazine, then we iterate over each character of ransom note, check whether it is available in the count, if not immediately return false. If present in the count,...

Read

August 25, 2022

Compare version numbers

First we split 2 versions with . and loop over the minimum number of both lenght, check whether one or two is bigger then return immediately. If both are equal, then we check whether we...

Read

August 25, 2022

Count servers that communicate

We iterate over each row, and check if we have another 1 in the row, then we add both of them in the result count. We do the same thing for column, and iterate over it to find another value for 1 and...

Read

August 24, 2022

Rotate list

We will first iterate over the list to count the number of the nodes. Then took k and mod it with the count for mitigate overflow. Then we took 2 pointer, first one we iterate k times and then start...

Read

August 24, 2022

Power of three

We will devide the number by 3 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:...

Read

August 23, 2022

Palindrome linked list

We will iterate over the whole list, and add the result to an array. Then we check whether the array is palindrome or not and return that value. Time Complexity: O(n) Space...

Read
... 71 72 73 74 75 ...