As reported: Arista Networks round 1 (online, 1 hour, 2025): two easy-to-medium questions after resume questions; this was the first.
Given an integer array nums and an integer k, return the maximum sum of any k consecutive elements.
Example 1
nums = [100,200,300,400], k = 2 -> 700
Example 2
nums = [1,4,2,10,23,3,1,0,20], k = 4 -> 39
4 + 2 + 10 + 23 = 39.
Constraints: 1 ≤ k ≤ nums.length ≤ 10^5; −10^4 ≤ nums[i] ≤ 10^4.
Code runner format: two lines — nums as a JSON array and k. Implement maxSumOfK(nums, k); the harness prints the maximum sum.