Tap here to switch tabs
Problem
Submissions

Problem: Power of Heroes

Power of Heroes asks you to sum the power of every nonempty group in an array, where each power is the square of its maximum strength times its minimum strength. Return the result modulo a large prime.

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

Power of Heroes asks you to sum the power of every nonempty group in an array, where each power is the square of its maximum strength times its minimum strength. Return the result modulo a large prime.

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