Tap here to switch tabs
Problem
Submissions

Problem: Power of Heroes

Try to solve the Power of Heroes problem.

Statement

You are given an integer array nums representing the strength of various heroes.

The power of a nonempty group of heroes is defined as the product of the square of the maximum strength in the group and the minimum strength in the group. Specifically, for a group with maximum value MM and minimum value mm, its power is M2imesmM^2 imes m.

Return the sum of the powers of all nonempty groups of heroes. Since the answer may be very large, return it modulo 109+710^9 + 7.

Constraints:

  • 1≤1 \leq nums.length ≤105\leq 10^5

  • 1≤1 \leq nums[i] ≤109\leq 10^9

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Power of Heroes

Try to solve the Power of Heroes problem.

Statement

You are given an integer array nums representing the strength of various heroes.

The power of a nonempty group of heroes is defined as the product of the square of the maximum strength in the group and the minimum strength in the group. Specifically, for a group with maximum value MM and minimum value mm, its power is M2imesmM^2 imes m.

Return the sum of the powers of all nonempty groups of heroes. Since the answer may be very large, return it modulo 109+710^9 + 7.

Constraints:

  • 1≤1 \leq nums.length ≤105\leq 10^5

  • 1≤1 \leq nums[i] ≤109\leq 10^9