Sum of Array Plus One
Given an array of integers, compute the sum of all elements of the array after incrementing each element by one. Return this total sum.
[ [ 1, 2, 3 ] ]
Explanation. Each element of the array [1, 2, 3] is incremented by 1 to become [2, 3, 4]. The sum of [2, 3, 4] is 9.
[ [ 0, -1, -2 ] ]
Explanation. Each element of the array [0, -1, -2] is incremented by 1 to become [1, 0, -1]. The sum of [1, 0, -1] is 0.
[ [ 1000, -1000 ] ]
Explanation. Each element of the array [1000, -1000] is incremented by 1. So the array becomes [1001, -999]. The sum of [1001, -999] is 2.
[ [ -100 ] ]
Explanation. The element -100 is incremented by 1, becoming -99. Thus the sum is -99.
[ [ 10, 20, 30 ] ]
Explanation. Each element of the array [10, 20, 30] is incremented by 1 to become [11, 21, 31]. The sum of [11, 21, 31] is 63.
Follow-up: Can you solve the problem in one line using functional programming constructs like map and reduce?
- `1 <= array.length <= 1000`\n- `-1000 <= array[i] <= 1000`, where `array[i]` is the ith element of the array.
- Views
- 3