Skip to content
Onsite

Sum of Index

EasyP3Coding

Let N be the length of arr (only the length matters, not the values). For each index i from 0 to N - 1, compute the sum of i + j over every index j from 0 to N - 1. Return the N sums in order. For N = 3 the answer is [3, 6, 9].

Example 1

Input
arr = [7,7,7]
Output
[3,6,9]
Why
i = 0: 0+1+2 = 3. i = 1: 1+2+3 = 6. i = 2: 2+3+4 = 9.

Example 2

Input
arr = [1]
Output
[0]

Example 3

Input
arr = [1,2]
Output
[1,3]

Constraints

  • 1 <= arr.length <= 10^5

Hints

Run checks the 3 visible tests, Submit all 8.