
Given an integer array nums, calculate its amplitude. The amplitude of an array is defined as the mathematical difference between its maximum element and its minimum element. If the array contains only one element, its amplitude is 0.
Write an efficient algorithm to find this value in a single pass.
Explanation: The maximum element in the array is 12 and the minimum element is 2. The amplitude is 12 - 2 = 10.
Explanation: The maximum element is 7 and the minimum element is 7. The amplitude is 7 - 7 = 0.
Explanation: The maximum element is 15 and the minimum element is -12. The amplitude is 15 - (-12) = 27.
Access the full code editor, ThinkBuddy AI hints, and track your progress.