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

Sudoku solver

We will use 3 hashset to store the value of rows, columns and boxes. For rows and columns hashset we will use the row and column number as key. For square hashset, we can use the integer division of...

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

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

Clumsy factorial

If we calculate some values, then we will notice some pattern. Here are some calculations- From this we can create the following method to calculate the clumsy factorial. Time Complexity:...

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

Minimum height trees

We will first create an adjacency list from the edge list. Then we start BFS from the leaf nodes, and whenever we visit a node, we add this to a list for current leaves, and decreasing the node count...

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

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

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