Sum of Subsequence Widths
Solve this the way you would in the interview: out loud, on a timer, with an AI interviewer asking follow-ups while you code. You get a scored report at the end.
Practice this as a mock interviewFree to start, no account neededProblem
The **width** of a sequence is its largest element minus its smallest element.
Given an integer array nums, consider every non-empty subsequence (any subset of positions, keeping their order). Return the sum of the widths of all of them. Subsequences taken from different position sets count separately even if they contain the same values.
There are 2^n - 1 subsequences, so enumerate nothing: find each element's total contribution. Return the sum modulo 1_000_000_007.
Examples
Constraints
- 1 <= nums.length <= 10^5
- 1 <= nums[i] <= 10^5
What the interviewer grades
A correct solution is one of five scores. The report also grades problem understanding (did you clarify inputs and edge cases before coding), problem solving, communication while you work, code quality, and testing. See a sample report, or read up on the pattern in the lessons.