nums
.mod
to 10^9 + 7
for taking modulo.sumWidths
to 0, which will store the final result.i
.
i
and for n - i - 1
(where n
is the length of nums
), taking modulo mod
.sumWidths
the contribution of nums[i]
as a maximum, which is nums[i] * (2^i - 1)
.sumWidths
the contribution of nums[i]
as a minimum, which is nums[i] * (2^(n - i - 1) - 1)
.mod
after each addition and subtraction.sumWidths
as the final answer.