Find the sum of a contiguous segment whose digits satisfy a maximum-range condition.
Problem
Given an array of integers, choose a contiguous subarray whose values satisfy the problem's digit-range condition, and return the sum of the chosen subarray.
The exact selection rule is based on the range of digits present in the numbers of the subarray. A valid subarray is one that maximizes that digit-range criterion among all contiguous subarrays.
Your task is to compute the sum of integers in the best valid subarray.
Goal
Return the sum of the contiguous subarray that meets the maximum digit-range requirement.
If multiple subarrays are equally valid under the criterion, any one with the correct maximum range is acceptable as long as the returned sum matches that chosen subarray.
Input Format
- An integer array
nums. - The array represents the sequence to inspect.
You may assume the input is already well-formed.
Output Format
- Return an integer representing the sum of the selected contiguous subarray.
Constraints
1 <= nums.length.- Values are integers.
- Use a solution that is efficient enough for interview settings.
Note: The exact bounds are not available from the source metadata, so these constraints are intentionally generic.
Example 1
Input
nums = [3, 1, 4, 1, 5]
Output
14
Explanation
One valid best segment is the full array, whose sum is 14.
Example 2
Input
nums = [2, 7, 1, 8, 2, 8]
Output
28
Explanation
The best contiguous segment can be the entire array, giving sum 28.
Premium problem context
Unlock deeper context for this problem
Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.