Find Second Largest Number in Array

In this tutorial, I am going to discuss the easiest way to find second largest number in array.

Given an array of integers. The array is unsorted. Write a java code to find second highest number in an array.

For example –

Input – arr[] = { 1, 9, 5, 2, 8, -1, 3, 55}

Output: 9

In this example, we have given an unsorted array of integers. The second largest number in this array is 9.

Find GCD of Two Numbers using Recursion – Java Code

How to find GCD of two numbers. In this tutorial, I am going to discuss multiple approaches to find GCD of two numbers using Recursion.

Given two input integers, we have to write a code to find GCD of two numbers using recursion.

For example:

Input  n1 : 36    n2 : 54

Output 18

Explanation :

The divisiors of 36 are 1, 2, 3, 4, 6, 9, 12, 18, 36  and the divisiors of 54 are 1,  2,  3,  6,  9,  18,  27,  54.

Common divisors are 1, 2, 3, 6, 9, 12 and 18.

The GCD (Greatest Common Divisior) for 36 and 54 is 18.

For this program, I assume you are familiar with the concept of recursion. If you don’t know about recursion then check my previous post on recursion vs iteration.