Monday, 12 December 2016

Factorial of Number using Recursion in Java

Find Factorial of Number. OR
Java Program to Find Factorial of Number. OR
Recursive Program to find Factorial of Number.


A factorial is a function that multiplies a number by every number below it.

Factorial of 5
5! = 5 * 4 * 3 * 2 * 1 = 120.

Factorial of 3
3! = 3 * 2 * 1 = 120.

Note: The value of 0! is 1

Below you can get Factorial of number till 20.
factorial of numbers from 1 to 20 chart
Factorial of numbers from 1 to 20 chart

Sunday, 11 December 2016

Print Matrix Diagonally OR Diagonal order of Matrix.

Print Matrix Diagonally. OR
Loop diagonally through two dimensional array. OR
Traverse an array diagonally. OR
Print elements of Matrix in Diagonal order.


Given a Matrix / 2D array, Print all elements of Matrix in Diagonal order. Lets understand Diagonal order of Matrix graphically.

Saturday, 3 December 2016

Find a Saddle point in Matrix

Find Saddle point in a matrix


Given a matrix of n x n size, Find saddle point of matrix.

What is Saddle point of Matrix?

Element is said to be Saddle point of Matrix if it is both a minimum of its row and a maximum of its column or vice versa.

A matrix may have 1 or 2 saddle points or may not have a saddle point.
Lets understand what will be input and expected output with the help of an example.


Friday, 2 December 2016

Print nodes at K distance from Leaf node in Binary tree.

Print nodes at K distance from Leaf in binary tree. OR
Print all nodes that are at distance k from a leaf node.


Given a Binary Tree, Print all Nodes that are at K distance from leaf node in Binary Tree. Lets understand what will be input and expected output with the help of an example.


If k = 1. It means we need to print all nodes that are at distance 1 from Leaf node.

In Case 2, we have 4 leaf nodes (Node 1, Node 10, Node 5, Node7).
Node at distance K that is Node at distance 1 from leaf Node 1 is Node 2 (Print 2)
Node at distance K that is Node at distance 1 from leaf Node 10 is Node 9 (Print 9)
Node at distance K that is Node at distance 1 from leaf Node 5 is Node 6 (Print 6)
Node at distance K that is Node at distance 1 from leaf Node 7 is Node 6 (6 already printed, ignore)