I have a requirement where I have to find an element from an array that has maximum distance in occurrence.
If there are two terms that were equally searched, the return term has the longest distance between when it was first and last searched.
Given the following array
[‘C++’, ‘Java’, ‘C#’, ‘C#’, ‘Java’, ‘Python’, ‘C#’, ‘Java’]
Our Program should return “Most searched term is Java”
Note: Both ‘Java’ and ‘C#’ were searched 3 times, but the program should return ‘Java’ as distance
between its first and last search is greater than that of ‘C#’.
I tried searching google, I can find the distance (6) but couldn't return the value (Java).