subject

Given an integer n and an array a of length n, your task is to apply the following mutation to a: Array a mutates into a new array b of length n.
For each i from 0 to n - 1, b[i] = a[i - 1] + a[i] + a[i + 1].
If some element in the sum a[i - 1] + a[i] + a[i + 1] does not exist, it should be set to 0. For example, b[0] should be equal to 0 + a[0] + a[1].
Example
For n = 5 and a = [4, 0, 1, -2, 3], the output should be mutateTheArray(n, a) = [4, 5, -1, 2, 1].
b[0] = 0 + a[0] + a[1] = 0 + 4 + 0 = 4
b[1] = a[0] + a[1] + a[2] = 4 + 0 + 1 = 5
b[2] = a[1] + a[2] + a[3] = 0 + 1 + (-2) = -1
b[3] = a[2] + a[3] + a[4] = 1 + (-2) + 3 = 2
b[4] = a[3] + a[4] + 0 = (-2) + 3 + 0 = 1
So, the resulting array after the mutation will be [4, 5, -1, 2, 1].
Input/Output
[execution time limit] 3 seconds (java)
[input] integer n
An integer representing the length of the given array.
Guaranteed constraints:
1 ≤ n ≤ 103.
[input] array. integer a
An array of integers that needs to be mutated.
Guaranteed constraints:
a. length = n,
-103 ≤ a[i] ≤ 103.
[output] array. integer
The resulting array after the mutation.

ansver
Answers: 2

Another question on Computers and Technology

question
Computers and Technology, 21.06.2019 21:00
You turn your computer on and the computer will not boot up where is something you should do to diagnose the problem?
Answers: 1
question
Computers and Technology, 22.06.2019 04:30
Which of the statements below is true? the formatting, standard, and drawing commands are unavailable. the formatting, standard, and drawing commands have been used. the formatting, standard, and drawing toolbars are displayed. the formatting, standard, and drawing toolbars are hidden.
Answers: 1
question
Computers and Technology, 22.06.2019 20:00
What is used to analyze and summarize your data without graphical support
Answers: 1
question
Computers and Technology, 22.06.2019 22:30
Who needs to approve a change before it is initiated? (select two.) -change board -client or end user -ceo -personnel manager -project manager
Answers: 1
You know the right answer?
Given an integer n and an array a of length n, your task is to apply the following mutation to a: A...
Questions
question
Mathematics, 15.12.2020 06:10
question
Social Studies, 15.12.2020 06:10
question
Mathematics, 15.12.2020 06:10
question
Engineering, 15.12.2020 06:10
question
Health, 15.12.2020 06:10
question
English, 15.12.2020 06:10
question
Biology, 15.12.2020 06:10
Questions on the website: 13722361