Problem statement

https://binarysearch.com/problems/All-Sublists-Sum/

Solution

For each index we can calculate how many subarrays with this index we have.

Complexity

It is O(n) for time and O(1) for space.

Code

class Solution:
    def solve(self, nums):
        n = len(nums)
        return sum(x*(i+1)*(n-i) for i, x in enumerate(nums)) % (10**9 + 7)