BasicsDispersionGoogleMetaJane Street
Problem
Implement range_and_midrange(x) returning (max(x) - min(x), (max(x) + min(x)) / 2) as a tuple of Python floats.
Why It Matters: Range measures total spread and midrange locates the exact center between extrema—commonly used in quick data-quality sanity checks.
Function Signature
def range_and_midrange(x: list[float]) -> tuple[float, float]:
Sample Input & Output
Example 1: Mixed Negative & Positive Values
Input:
x = [-4.0, 2.0, 10.0, 6.0]
Expected Output:
(14.0, 3.0)
Explanation: Min is -4.0, max is 10.0 → range is 10 - (-4) = 14.0, midrange is (-4 + 10) / 2 = 3.0.
Example 2: Constant Sequence
Input:
x = [7.0, 7.0, 7.0]
Expected Output:
(0.0, 7.0)
Explanation: Min and max are both 7.0, so range is 0.0 and midrange is 7.0.
Constraints & Edge Cases
- Return
(data_range, midrange)as floats. - Return
(float, float). - If all values are equal, range is
0.0and midrange equals that constant value.
Constraints & Evaluation Criteria
- Return `(data_range, midrange)` as floats.
Hints
Python 3⌘/Ctrl+Enter to Run · ⌘/Ctrl+Shift+Enter to Submit
Loading Code Editor...
+1 Hidden Submit Case
Input / Scenario
[4, 10, 2, 8]
Expected Output / Criteria
(8.0, 6.0)