## Maximum Depth of N-ary Tree Leetcode Solution

In this problem, we are given an N-ary tree, that is, a tree that allows nodes to have more than 2 children. We need to find the depth of a leaf farthest from the root of the tree. This is called maximum depth. Note that the depth of a path …

## Minimum Depth of Binary Tree Leetcode Solution

In this problem, we need to find the length of the shortest path from the root to any leaf in a given binary tree. Note that the “length of the path” here means the number of nodes from the root node to the leaf node. This length is called Minimum …

## Course Schedule II – LeetCode

You have to attend n number of courses (from 0 to n-1) where some of the courses have prerequisites. For instance: pair [2, 1] represents to attend course 2 you must have taken course 1. Given an integer n representing the total number of courses and the list of courses …

## Find Maximum Level sum in Binary Tree

Problem Statement The problem “Find Maximum Level sum in Binary Tree” states that you are given a binary tree with positive and negative nodes, find the maximum sum of a level in the binary tree. Example Input 7 Explanation First Level : Sum = 5 Second Level : Sum = …

## Level order traversal using two Queues

Problem Statement The problem “Level order traversal using two Queues” states that you are given a binary tree, print its level order traversal line by line. Examples Input 5 11 42 7 9 8 12 23 52 3 Input 1 2 3 4 5 6 Algorithm for Level Order Traversal …

## Find the smallest binary digit multiple of given number

Problem Statement The problem “Find the smallest binary digit multiple of given number” states that you are given a decimal number N. So find the smallest multiple of N that contains only the binary digits ‘0’ and ‘1’. Example 37 111 A detailed explanation can be found below in the …

## Minimum Operations to convert X to Y

Problem Statement The problem “Minimum Operations to convert X to Y” states that you are given two numbers X and Y, it is needed to convert X into Y using following operations: Starting number is X. Following operations can be performed on X and on the numbers that are generated …

## Minimum time required to rot all oranges

Problem Statement The problem “Minimum time required to rot all oranges” states that you are given a 2D array, every cell has one of the three possible values 0, 1 or 2. 0 means an empty cell. 1 means a fresh orange. 2 means a rotten orange. If a rotten …

## Distance of nearest cell having 1 in a binary matrix

Problem Statement The problem “Distance of nearest cell having 1 in a binary matrix” states that you are given a binary matrix(containing only 0s and 1s) with at least one 1. Find the distance of the nearest cell having 1 in the binary matrix for all the elements of the …

## An Interesting Method to generate Binary Numbers from 1 to n

Problem Statement The problem “An Interesting Method to generate Binary Numbers from 1 to n” states that you are given a number n, print all the numbers from 1 to n in binary form. Examples 3 1 10 11   6 1 10 11 100 101 110 Algorithm The generation …