nums. A slice is a non-empty run of consecutive elements of the array.
Take every slice of odd length (1, 3, 5, …), compute the sum of each one, and return the grand total of all those sums.nums=[2, 6, 1, 3] → 31
The odd-length slices are the four single elements (12 in total), [2,6,1] = 9 and [6,1,3] = 10. Altogether 12 + 9 + 10 = 31.
nums=[7] → 7
The only slice is the element itself.
nums=[1, 1, 1] → 6
The three single elements give 3, the whole array gives another 3, so 6 in total.
nums.length ≤ 10⁵nums[i] ≤ 10⁴nums=[2, 6, 1, 3]
31
Run checks the first 3 tests in your browser. Submit checks all 106 tests on the server, hidden ones included.