← 返回 microsoft 的题目列表Optimize Maximum Distance
类型:online_judge
Given an integer array, find the maximum distance between two distinct elements, ensuring that the program runs in less than 2 seconds, especially when the array length is 75,000.
Input
An integer array A.
Output
An integer representing the maximum interval distance between two distinct elements i and j, where A[i] ≠ A[j].
Example
Input: [4, 6, 2, 2, 6, 6, 4]
Output: 5
Notes
For the input [1, 1, 1, 1], the output should be 0.
Assume the length of the array N, with elements ranging from -10^9 to 10^9.
Example
Input
[4, 6, 2, 2, 6, 6, 4]