Sponsored
Sponsored
Use these hints if you're stuck. Try solving on your own first.
Iterate over all substrings in <code>O(n * n)</code>.
For each substring, try to calculate the sum of the mapped values in <code>O(1)</code>.
To do the above, use a partial sum array.