Problems
September 1, 2022
Next permutation
We will take a pointer at the end of the list and move towards front until we a bigger value than the previous. If we reach all the way till the beginning, the the list is already in decreasing...
ReadSeptember 1, 2022
Simple bank system
We will create a list in the class to track the balance of each account. Then on each operation we will check whether the account number is out or range or money is overflown to that account, if yes...
ReadSeptember 1, 2022
Zigzag conversion
We will create an array with empty string for each row. Then we also have a direction value, which will be down at the beginning. Then we start from position 0, add items in each row until we reach...
ReadAugust 31, 2022
Continuous subarray sum
We will take a hashmap and keep the reminder along with their index in it. As a base case, we will take the subarray sum as 0 and keep the index -1 as we don't added anything yet in the subarray sum....
ReadAugust 31, 2022
Rearrange words in a sentence
We will split the word with space as delimeter, sort them according to their length, join then again with space, finally return the capitalize string.
Time Complexity: O(nlog(n))
...
August 31, 2022
Subarray sum equals k
This problem can't be solved using sliding window as it is not only positive, or only negative or sorted. So, we iterate over each item in the input, calculate prefix sum and store it in a hashmap....
ReadAugust 30, 2022
Furthest building you can reach
We will take the ladders for the longest obstackles. First we take the obstackles in a heap, then take the smallest, if the diff is less than or equals to the bricks, we take the bricks, else we take...
ReadAugust 30, 2022
Get equal substrings within budget
We will take 2 pointer, we will forward our right pointer, added the difference of s and t in a running sum and until it is less than max cost, we forward the right pointer. Then we forward the left...
ReadAugust 30, 2022
Maximum xor of two numbers in an array
we will create a mask of first character 1 for all 32 position in a 32 bit integer. Then we created hashset to calculate which number has the largest most significant bit. Then we create a temporary...
ReadAugust 30, 2022
Minimum moves to make array complementary
First we create an overlay lookup hashmap of size 2limit+2, as our minimum boundary of change is 2 and maximum is 2limit. Then we iterate over the elements in pair, take the first and last element,...
Read