You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
i * (N-i) + (N-i) because there are N-i subarrays with arr[i] as first element
and i * (N-i) subarrays with arr[i] as a not-first element. arr[i] appears in
(N-i) subarrays for each preceding element and therefore we have i*(N-i).
Suppose i * (N-i) + (N-i) is `total`. Ceil(total / 2) is the number of odd-length subarrays and Floor(total / 2) is the number of even-length subarrays.
When total is odd, there is one more odd-length subarray because of a single-element subarray.
For each number, we multiply its value with the total number of subarrays it appears and