Sum of subarray ranges
Your task
Given an integer array, the range of a contiguous subarray is its maximum element minus its minimum element. Return the sum of the ranges over all contiguous subarrays. The array has at most 1000 elements; values may be negative. The answer fits in a 64-bit signed integer.
Examples
sum_subarray_ranges(arr: list[int]) -> intExample 1
Input
sum_subarray_ranges([1, 2, 3])Output
4