values and a number size. Consider every group of exactly size elements of the array (elements at different indices are different even if their values are equal).
The tightness of a group is the smallest absolute difference between two of its elements.
Return the sum of tightness over all such groups. The answer can be huge, so return it modulo 10⁹ + 7.values=[1, 4, 6], size=2 → 10
There are three pairs: {1, 4} with gap 3, {1, 6} with gap 5 and {4, 6} with gap 2. The sum is 3 + 5 + 2 = 10.
values=[5, 1, 3, 9], size=3 → 10
The triples: {1, 3, 5} → 2, {1, 5, 9} → 4, {3, 5, 9} → 2, {1, 3, 9} → 2. The sum is 10.
values=[7, 7, 2], size=3 → 0
The only triple has two 7s, so its smallest gap is 0.
values=[1, 4, 6], size=2
10
Run checks the first 3 tests in your browser. Submit checks all 116 tests on the server, hidden ones included.