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