Walmart Phone Interview

Difficulty: EASYCategory: InterviewExperienceFrequency: 1Asked On 2021-07-24Added By Anonymous
Source: Link

Given an array a of n integers, return an array of integers which contains [1st integer, sum of next 2 integers (2nd, 3rd), sum of next 3 integers (4th, 5th, 6th)]


input size n

[1,6,8,5,9,4,7,2]

Output size m

[1,14,18,9]


I think this is a two pointers and map question,

// i 0, j 0

//i 1, j 1,2

//i 2, j 3,4,5

//i 3, j 6,7,8,9


Can you share your idea and code? Thanks.

Comments