Maximum difference between first and last indexes of an element in array
Given an array of n integers. The task is to find the difference of first and last index of each distinct element so as to maximize the difference. Examples: Input : {2, 1, 3, 4, 2, 1, 5, 1, 7} Output : 6 Element 1 has its first index = 1 and last index = 7 Difference = 7 - 1 = 6 Other elements have