Find Nth Ugly Number

Given a number N, we have to write a code to find the Nth ugly number.

What is Ugly Numbers?

Ugly numbers are positive numbers whose prime factors only include 2, 3, 5. In simple words, The number which can be represented as the product of 2, 3 and 5 are ugly numbers (2^i * 3^i * 5^i).

For Example –

Input : n = 10, Output : 12

12 is the 10th ugly number. The first 10 ugly numbers are 1, 2, 3, 4, 5, 6, 8, 9, 10, 12.

Note:  

1 is typically treated as an ugly number.

n does not exceed 1690.

Check If Two Binary Trees are Identical (Same Tree)

How to Check If Two Binary Trees are Identical.

Given two binary trees, write a code to check if they are the same or not.

Two binary trees are considered the same if they are structurally identical and the nodes have the same value.

For example: (Check the image)

Example 1: true

In this first example, Both the trees are same. They have the same structure as well as their node values are same.

Example 2: false

In the second example, Both the trees are structurally same but the value of left children of tree A is not equal to tree B.

Example 3: false

Both the trees are structurally not identical.

Reverse a Stack using Recursion

How to reverse a stack using Recursion? In this tutorial, I am going to discuss this interesting problem.

Given a stack of integers, we have to write a code to reverse them using recursion. For solving this problem, we don’t have to use any loop constructs (For, While etc.) or any additional data structure.

You can use stack methods like push, pop, isEmpty to solve this problem.

Reverse a stack using recursion