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).

Find Duplicate Characters in a String | Java Code

Given an input string, Write a java code to find duplicate characters in a String.

For example :

Example 1:

Input    : “Java”
Output : a

The character a appears more than once in a string.

Example 2:

Input : “programming”
Output : m,g,r

These three characters (m, g, r) appears more than once in a string.