Sum of subarray ranges
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.
Implement
sum_subarray_ranges(arr: list[int]) → intExamples
in
[[1,2,3]]out4What a strong answer looks like
State your approach and its time/space complexity out loud before you optimize. Handle the edge cases (empty input, duplicates, overflow), and say why you chose this over the brute force. Green tests are the floor, not the grade.
0:00 of about 35 min
solution.py
InputExpectedGot
[[1,2,3]]4not run yetsample