Class Solution

  • All Implemented Interfaces:

    
    public final class Solution
    
                        

    891 - Sum of Subsequence Widths\.

    Hard

    The width of a sequence is the difference between the maximum and minimum elements in the sequence.

    Given an array of integers nums, return the sum of the widths of all the non-empty subsequences of nums. Since the answer may be very large, return it modulo <code>10<sup>9</sup> + 7</code>.

    A subsequence is a sequence that can be derived from an array by deleting some or no elements without changing the order of the remaining elements. For example, [3,6,2,7] is a subsequence of the array [0,3,1,6,2,2,7].

    Example 1:

    Input: nums = 2,1,3

    Output: 6 Explanation: The subsequences are 1, 2, 3, 2,1, 2,3, 1,3, 2,1,3. The corresponding widths are 0, 0, 0, 1, 1, 2, 2. The sum of these widths is 6.

    Example 2:

    Input: nums = 2

    Output: 0

    Constraints:

    • <code>1 <= nums.length <= 10<sup>5</sup></code>

    • <code>1 <= numsi<= 10<sup>5</sup></code>

    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
    • Field Summary

      Fields 
      Modifier and Type Field Description
    • Constructor Summary

      Constructors 
      Constructor Description
      Solution()
    • Enum Constant Summary

      Enum Constants 
      Enum Constant Description
    • Method Summary

      Modifier and Type Method Description
      final Integer sumSubseqWidths(IntArray nums)
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait