values and an integer limit. Consider every way to choose a group of 1 to limit elements from the array (elements are told apart by position, even if their values are equal). For each group, add its minimum to its maximum.
Return the total of these numbers over all groups. Since it can be huge, return it modulo 10⁹ + 7.values=[4, 1, 3], limit=2 → 32
Single-element groups give 8 + 2 + 6 = 16. Pairs: {4, 1} → 5, {4, 3} → 7, {1, 3} → 4, another 16. The answer is 32.
values=[2, 2], limit=1 → 8
Only single-element groups: each has minimum and maximum 2, so 4 + 4 = 8.
values=[0, 5, 10], limit=3 → 70
values=[4, 1, 3], limit=2
32
Run checks the first 3 tests in your browser. Submit checks all 99 tests on the server, hidden ones included.