1040. Sum of first last element in array
Given an integer array nums, return the sum of the 1st and last element of the array.
Example 1:
Input: nums = [2, 3, 4, 5, 6]
Output: 8
Explanation: 1st element = 2, last element = 6, sum = 2 + 6 = 8.
Example 2:
Input: nums = [2]
Output: 4
Explanation: 1st element = last element = 2, sum = 2 + 2 = 4.
Now Your Turn!
Pick the correct output for the given inputInput: nums = [-1, 2, 4, 1]
Still unsure what the problem is asking ?
Let’s go through a few more examples, step by step, to make it clearer.
Constraints:
- 1 <= Number of elements in nums <= 100
- -100 <= nums[i] <= 100