Problems
September 16, 2022
Design an atm machine
We will store all the notes to an array, which will be the attribute of the class. We will also have a lookup notes dictionary. For deposit, we will just increase the number of bank notes in the ATM...
ReadSeptember 16, 2022
Stone game
When the piles remaining are piles[i], piles[i+1], ..., piles[j], the player who's turn it is has at most 2 moves. The person who's turn it is can be found by comparing j-i to N modulo 2. If the...
ReadSeptember 15, 2022
Validate ip address
We will split the string with .
and :
. If the number of chunk is not 4 for ipv4 or not 8 for ipv6, we return Neither. Otherwise, we check check separately, for ipv4, each...
September 15, 2022
Find original array from doubled array
We will first count the number of elements in the changed array. Then we will look for 0. If the count of 0 is odd, we return empty array, else we add half of them in our result. Then we sort the...
ReadSeptember 14, 2022
Pseudo palindromic paths in a binary tree
We will start from root and traverse the root with DFS. In the process we will count the occureance of each node's value. Whenever we reach a root node, we will check for pseudo palindrome, if found...
ReadSeptember 14, 2022
Spiral matrix II
First we will initialize the matrix with 0 value in all of it's position. Then we will determine the value of left, right, top and bottom. Then we assing the value k from the top row to our matrix,...
ReadSeptember 14, 2022
Insufficient nodes in root to leaf paths
We will traverse the node with DFS and each time we reach a leaf node, we check for the insufficient node, if the node is insufficient, we delete it from the tree. After traversal of whole tree, we...
ReadSeptember 13, 2022
Is graph bipartite
If we run BFS, then every level of traversal will have a different color. So we start from node 0, then start traversal using BFS and on each level, we alternate the color. In the process if we find...
ReadSeptember 13, 2022
Range sum query immutable
We will store the nums as a class property and each time there is a query, we sum up the range in between and return the result.
Time Complexity: O(n)
Space Complexity:...
September 13, 2022
Reorder data in log files
We will create two different array, one for the letter logs and another for the digits logs. Then we iterate over all the logs and separate them. Then we sort the letters log, first by the content,...
Read