Problems


September 2, 2022

Sum root to leaf numbers

We will run DFS from root to leaf, along in the way, we calculate the number for root to leaf value. Once we reach the leaf, we add it to our result. Finally we return the result after traversal is...

Read

September 2, 2022

Average of levels in binary tree

We will run BFS and after traversal of each level, we append the average in our result, and finally return it after the end of traversal. Time Complexity: O(n) Space Complexity:...

Read

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...

Read

September 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...

Read

September 1, 2022

N-ary tree level order traversal

We will run BFS in each level and append the values in a result list, and return the list when traversal is done. Time Complexity: O(n) Space Complexity: O(n)

Read

September 1, 2022

Insertion sort list

We will create a dummy node and attach it at the beginning to make our life easier. Then we take 2 pointer, previous and current, previous will be our head and current will be the next node of...

Read

September 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...

Read

September 1, 2022

Integer to roman

We will create 2 loopup table, one for ONES and another for FIVES. Then we start from least significant bit, check the value is 4 if we mod it by five, then take the value from FIVES lookup table,...

Read

September 1, 2022

Minimum moves to equal array elements

Elevating n-1 elements is essensially same as decreasing 1 element. Thus we must decrease everything to the minimum value to get the result. Time Complexity: O(n) Space Complexity:...

Read

September 1, 2022

4sum

We will sort the array and start from first element i, the take the next element j which is not equal to i, then take the next element as l, and the last element of the list as r, added them, compare...

Read
... 67 68 69 70 71 ...