← 返回 bytedance 的题目列表Maximum Absolute Difference in Array
类型:online_judge
Given an integer array, find the maximum absolute difference between any two elements in the array. Return this maximum difference. Design an optimal solution. Assume the array contains at least two elements.
Input:
An array arr of integers where 2 <= len(arr) <= 10^5, -10^9 <= arr[i] <= 10^9.
Output:
An integer representing the maximum absolute difference between any two elements in the array.
Example:
Input: [-10, -5, 0, 5, 10]
Output: 20
Input: [1, 3, -1]
Output: 4
Please note, you should design an O(n) time complexity algorithm.
Example
Input
-10 -5 0 5 10