The solution I’m considering seems so simple that I’m wondering if I’m interpreting the problem correctly.
The problem is: Write a program that takes an array of integers and finds the length of a longest subarray all of whose entries are equal.
The solution I have in mind is to walk the array, maintaining a map of counts of unique entries. The longest value in the map is the length of the longest subarray. Time complexity O(n), space complexity O(n).
Is this a correct approach?
Also, may I assume that the entries in the longest subarray are not necessarily stored at contiguous indices in the original array?