Sponsored
Sponsored
Use these hints if you're stuck. Try solving on your own first.
Try something with sorting the array.
For a pair of array elements nums[i] and nums[j] (i < j), the power would be nums[i]*nums[j]^2 regardless of how many elements in between are included.
The number of subsets with the above as power will correspond to 2^(j-i-1).
Try collecting the terms for nums[0], nums[1], …, nums[j-1] when computing the power of heroes ending at index j to get the power in a single pass.