Remove Duplicates from Unsorted Array

Given an unsorted array of integers. Write a code to remove duplicates from unsorted array.

For example:

Input   :{5, 1, 2, 6, 4, 4, 5}
Output :{5, 1, 2, 6, 4}

In this example, 4 and 5 appear multiple times in an input array.

In the output, All the duplicates are removed and we have printed only distinct elements of an array.

Find Maximum Difference between Two Elements of an Array

Given an array of integers, find Maximum difference between two elements such that larger number appears after the smaller number. In this tutorial, I am going to discuss multiple approaches and their java code to find maximum difference between two elements.

For example :

Example 1:

arr = {2, 5, 15, 6, 4}
Output: 13

The difference between 15 and 2 is 13. Element 15 is greater than 2 and it satisfies our condition that larger number appears after the smaller number.

Example 2:

arr = {7, 9, 5, 6, 13, 2};
Output : 8

The difference between 13 and 5 is 8 (13-5).

Insertion Sort Program in Java

Insertion Sort Program in Java. Write a java program to sort an unsorted array using insertion sort.

In this tutorial, We are going to cover following points.

  • How insertion sort works?
  • Insertion sort program in java.
  • Video tutorial which explain insertion sort algorithm.

Let’s say we have an unsorted array and we want to sort this array using insertion sort. Let’s first understand how insertion sort works?

Input : {5, 4, 2, 9, 1}

Output : {1, 2, 4, 5, 9}