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].

Answers

Answer 1

Answer:

let a = [4, 0, 1, -2, 3];

let b = a.map( (e, i, arr) => (arr[i-1] || 0)+arr[i]+(arr[i+1] || 0) );

console.log(b);

Explanation:

The map operator is excellent for this. The || 0 operator prevents the undefined out of bounds value from ruining the result.

BTW this solution is in javascript. Other languages will presumably require more code.


Related Questions

Anyone who has an iPod touch and downloads apps from iTunes participates in Digital Commerce and is a digital consumer.

Answers

Problem can be solved if you know the problem and what the consumer looking for

Microsoft word 365 allows cells to be split into how many columns

Answers

Answer:

Microsoft word 365 allows two columns

Yep it’s that I agree with him because I agree with him because I agree with him because I know his answer is right so I agree with him:)

define excretion in plants​

Answers

Answer:

excretion is the removal of waste from plants

Explanation:

Plants also produce waste but they produce waste very slowly and in very small amounts

They don't have any special organism for the removal of their waste

Their waste products are:

carbon dioxidewater vapouroxygen

The product of joint force development is a _____________.

Answers

Answer:

trained and capable joint force.

Explanation:

The joint force development policy is in regards to the training and recruitment of military officials, to improve or promote the growth and speedy development of recruits in the United States military.

Several aspects of military training are given to officials by joint parties from different but collaborating organizations. Joint education, deployment, and dissemination of employment various members of the armed forces are encouraged.

What is the main advantage of an MILC?

Answers

Answer:

What is the main advantage of an MILC?

Explanation:

MILC cameras combine some of the advantages of DSLR cameras along side the compactness, features and ease of use of point-and-shoot cameras. The main advantages are: A relatively compact and lightweight interchangeable lens camera. Utilizes a relatively large sensor (Micro Four Thirds, APS-C)

Hope that helped.

The four key stages with regards to data visualization workflow. Select one key stage and explain it briefly about that stage.Stage 1:Formulating your briefStage 2:Working with dataStage 3:Establishing your editorial thinkingStage 4:Developing your design solution

Answers

Answer:

The answer is below

Explanation:

Picking the stage 1.

Formulating your Design Brief is a stage that involves various activities such as planning, establishing, and commencing the project

Hence, at this stage, one has to do the followings

1.   Establish the context of the visualization

2.  Examine the conditions that will have an effect on the process

3.  Clarify the vision of the visualization

4.   Point out the event and manner of voice that is required

Write a program in c++ that plays a number guessing game with a Human user. The Human user will think of a number between 1 and 100, inclusive. The program will make guesses and the user will tell the program to guess higher or lower. A sample run of the program might look like this: Ready to play (y/n)? y Think of a number between 1 and 100. My guess is 50. Enter 'l' if your number is lower, 'h' if it is higher, 'c' if it is correct: h My guess is 75. Enter 'l' if your number is lower, 'h' if it is higher, 'c' if it is correct: h My guess is 88. Enter 'l' if your number is lower, 'h' if it is higher, 'c' if it is correct: l My guess is 81. Enter 'l' if your number is lower, 'h' if it is higher, 'c' if it is correct: c Great! Do you want to play again (y/n)? y Think of a number between 1 and 100. My guess is 50. Enter 'l' if your number is lower, 'h' if it is higher, 'c' if it is correct: l My guess is 25. Enter 'l' if your number is lower, 'h' if it is higher, 'c' if it is correct: h My guess is 37. Enter 'l' if your number is lower, 'h' if it is higher, 'c' if it is correct: c Great! Do you want to play again (y/n)? n The strategy that the program will use goes like this: Every time the program makes a guess it should guess the midpoint of the remaining possible values. Consider the first example above, in which the user has chosen the number 81: On the first guess, the possible values are 1 to 100. The midpoint is 50. The user responds by saying "higher" On the second guess the possible values are 51 to 100. The midpoint is 75. The user responds by saying "higher" On the third guess the possible values are 76 to 100. The midpoint is 88. The user responds by saying "lower" On the fourth guess the possible values are 76 to 87. The midpoint is 81. The user responds "correct" Additional Requirements The purpose of the assignment is to practice writing functions. Although it would be possible to write the entire program in the main function, your solution should be heavily structured. Most of the point penalties given on this assignment will be for not following the instructions below carefully. The main function must look exactly like this. Copy and paste this code into your file, and don't edit it: int main() { char response; cout > response; while (response == 'y') { playOneGame(); cout > response; } } The playOneGame() function should implement a complete guessing game on the range of 1 to 100. The lower and upper bounds of the range should be assigned to global named constants and then not used again in your code. In addition, you should implement the following helper functions to be invoked inside your playOneGame() function: void getUserResponseToGuess(int guess, char& result) The getUserResponseToGuess() function should prompt the user to enter 'h', 'l', or 'c' (as shown in the sample output). It should set its "result" parameter equal to whatever the user enters in response. It should do this ONE time, and should not do anything else. Note that printing the guess is part of the prompt. int getMidpoint(int low, int high) The getMidpoint() function should accept two integers, and it should return the midpoint of the two integers. If there are two values in the middle of the range then you should consistently chose the smaller of the two.

Answers

Answer:

the question is too long. dear

.mate

that’s too much to understand, could you make it more simple to read and understand?

A(n) ____ is built only after an engineer can prove sound design through structural analysis.

Answers

Answer:

no se

Explanation:

pues no se

Answer:

a prototype

Explanation:

We have seen that Internet TCP sockets treat the data being sent as a byte stream but UDP sockets recognize message boundaries. What are one advantage and one disadvantage of byte-oriented API versus having the API explicitly recognize and preserve application-defined message boundaries

Answers

Answer:

One advantage of byte-oriented APIs is that all byte of the data sent by the API is retrieved but for APIs with application-defined message boundaries, some bytes of data could be lost in the streaming process.

One disadvantage of byte-oriented APIs is the time it takes to resend a byte increases its propagation delay, while the is an advantage of the APIs with application-defined message boundaries as it does not have to resend any lost bytes of data, making it faster.

Explanation:

Note that byte-oriented APIs uses the TCP socket which resends lost bytes of data and application-defined message boundaries APIs uses the UDP protocol to send data but does not resend if lost.

Write a program that calculates taxi fare at a rate of $1.50 per mile. Your pro-gram should interact with the user in this manner:TAXI FARE CALCULATOREnter beginning odometer reading=> 78602.5Enter ending odometer reading=> 78622.7You traveled a distance of 20.2 miles. At $1.50 per mile,your fare is $30.30.

Answers

Answer:

print("TAXI FARE CALCULATOR\n")

beginning = float(input("Enter beginning odometer reading => "))

ending = float(input("Enter ending odometer reading => "))

distance = ending - beginning

fare = 1.50 * distance

print("You traveled a distance of %.1f" % distance + " miles. At $1.50 per mile, your fare is $ %.2f" % fare)

Explanation:

*The code is in Python.

Print the title

Ask the user to enter beginning and ending of the odometer reading. Calculate the distance by subtracting these values

Calculate the fare, multiply the distance by 1.50

Print the distance and fare in required format

Which statements about Excel's FV function are correct?
A. The FV function has five arguments, and their abbreviations are rate, nper, pmt, pv, and type.
B. If the number for the pmt argument is entered as a positive value and the pv value is zero, the FV value is negative.
C. If the interest rate is 10%, the rate argument can be entered as .1 or 10%.
D. All of the options are correct.

Answers

Answer:

. D)All of the options are correct.

Explanation:

Excel's FV function can be regarded as financial function that bring about the analysis and calculation of an investment Future's value.

It should be noted that it posses arguments,with abbreviations: rate, nper, pmt, pv, and type.

an Excel's FV function will have negative value If the number for the pmt argument is entered as a positive value and the pv value is zero,

Hence, all the given options are correct.

List two items that are required to make a text file into a bash script.

Answers

Answer:

Explanation:

First a header is needed indicating which bash will be used (sh, zsh, bash, etc.), then it is necessary to change the file extension so that the system recognizes it as an executable file and no longer as text

In order for the system to recognise the file as an executable file rather than a text file, a header indicating which bash will be used is first required (sh, zsh, bash, etc.).

What is bash script?

A file containing a succession of commands is called a bash script. The bash programme reads and processes these.

The computer programme runs line by line. For instance, you can use the command line to travel to a specific path, create a folder, and spawn a process inside of it.

Run the "cat" command and then use the redirection operator ">" and the filename to create a new file. You will now be asked to add data to this just created file. To save the file, type line and then hit "Ctrl+D."

A header stating which bash will be used is first necessary for the system to recognise the file as an executable file as opposed to a text file (sh, zsh, bash, etc.).

Thus, these are the two items that are required to make a text file into a bash script.

For more details regarding bash script, visit:

https://brainly.com/question/27962326

#SPJ2

Command-based operating systems include

Answers

Answer:

Cpu is the point of the computer

Explanation:

GOT IT REEEEEEEEEEEEE

A customer in a store is purchasing five items. The prices of the five items are Price of item 1 = $15.95 Price of item 2 = $24.95 Price of item 3 = $6.95 Price of item 4 = $12.95 Price of item 5 = $3.95 Write a program that holds the prices of the five items in five variables. Display each item’s price, the subtotal of the sale, the amount of sales tax, and the total. Assume the sales tax is 7%

Answers

Answer:

Follows are the code to this question:

#include<iostream>//defining a header file

using namespace std;

int main ()//defining a main method

{

float SubTotal,SalesTax,Total;//defining float variable for calculate the value

float item_1 = 15.95, item_2 = 24.95,item_3 = 6.95, item_4 = 12.95,item_5 = 3.95;//defining float variable and assign value

SubTotal = item_1+item_2+item_3+item_4+item_5;//use SubTotal to calculate the sum

SalesTax = SubTotal * 0.07;//use SalesTax to calculate 7% of SubTotal

Total = SubTotal + SalesTax ;//use Total to addd SubTotal and SalesTax

cout << "Price of item 1 : $"<< item_1 << endl;//print item_1 Price

cout << "Price of item 2 : $"<< item_2 <<endl;//print item_2 Price

cout << "Price of item 3 : $"<< item_3 <<endl;//print item_3 Price

cout << "Price of item 4 : $"<< item_4 <<endl;//print item_4 Price

cout << "Price of item 5 : $"<< item_5 <<endl;//print item_5 Price

cout <<"The SubTotal value is: $"<< SubTotal << endl;//print SubTotal value

cout <<"The SalesTax value is: $"<< SalesTax << endl;//print SalesTax value

cout << "The Total value is: $" << Total << endl;//print Total value

return 0;

}

output:

please find attached file.

Explanation:

In the above-given code, three float variable that are "SubTotal, SalesTax, and Total" is define for calculating and store its value, and in the next line, another five float variable " item_1, item_2, item_3, item_4, and  item_5" is declared that stores a float value which is defined in the question.

In the next line, the "SubTotal" variable is used to add the value of all items, and in the next line, the SalesTax is used to calculate the 7% of SubTotal and store its value. At the last, the "Total" variable is defined that adds the "SubTotal and SalesTax" value and uses the print method to print all variable values.

how many margins are on a page

Answers

I think its two, probably

Which class describes a container for an application?

Answers

Answer:

The "container class" would be the correct approach.

Explanation:

A class is known to have become a container class used to keep objects throughout memory via permanent networks, containing appropriate solutions of primitive functions and perhaps other containers This tends to have become a strong combination of predefined behavior and has a well-known framework.

Can you give an example of mail merge (letter) pls​​

Answers

Answer:

yes a mail merge letter is almost the same as a mail you write to someone but slightly different here is an example

Explanation:

Dear Spiderman

We have the following address on file for you

spiderman

The principal object of a hash function is __________ .
a. data integrity
b. compression
c. collision resistance
d. mapping messages

Answers

Answer:

a. data integrity

Explanation:

In Computer science, a hash function can be defined as any function which is used to map data by accepting a block of data with variable length size or arbitrary size as input to produce a fixed size hash values or codes.

Generally, when a block of data (input) of arbitrary size is hashed, the resulting hash values or codes is usually smaller than the input data. Thus, hash functions are considered to be a compression of data and as a result, sometimes called compression functions. Basically, the block size of a hash function typically ranges from 128 bits to 512 bits.

Some of the properties of a hash function are;

1. Pre-image resistance: this makes it practically impossible to reverse a fixed-size hash values to its initial arbitrary size. This property helps to maintain and enhance data integrity by making it difficult or impossible for an attacker to find the input data from a hash value.

2. Second pre-image resistance: this property makes it near impossible or very difficult to determine or decode another input data from a given set of input and hash values. Also, this helps to enhance data integrity.

3. Collision resistance: this is to make possible for all hash values to have a unique value. This simply means that, with this property it would be difficult for different input data to have the same hash value. Thus, it helps to create integrity in data management.

Hence, with the aforementioned properties, the principal object of a hash function is data integrity.

Hash functions in the computer world includes;

1. Message Digest (MD): it is a 128 bit hash function and comprises of the following; MD2, MD4, MD5, and MD6.

2. Secure Hash Function (SHA): it comprises of the following; SHA-0, SHA-1,SHA-2, and SHA-3.

3. Whirlpool: it comprises of the following; Whirlpool-0, Whirlpool-T, and Whirlpool. It is primarily a 512 bit hash function.

4. RACE Integrity Primitives Evaluation Message Digest (RIPEMD): it comprises of the following versions; RIPEMD, RIPEMD-128, and RIPEMD-160.

Write a program that reads in a line of text and outputs the line with all the digits in all integer numbers replaced with 'x'. Please enter a line of text: My userID is john17 and my 4 digit pin is 1234 which is secret My userID is john17 and my x digit pin is xxxx which is secret Notes: 1. If a digits is part of a word, then the digit is not changed to an 'x'. For example, john17 is NOT changed to johnxx. 2. You may assume that the text entered by the user will contain only letters (upper case or lower case), digits and spaces. 3. Think how to break down your implementation to functions.

Answers

Answer:

import re

def secret_pin_digit( ):

   user = input("Please enter a line of text: ")

   search_values = re.findall( "\d", user )

   for item in search_values:

       if int( item ) == "NAN":

           user.replace("item", "x")

   print( user )

Explanation:

The python function program above prompts the user for a string specifying the user id, username and the user pin. The digits in the string are replaced with an "x". This is used to hide the pin of a user

Not Answered 4.Not Answered Question Workspace Check My Work You purchase a new desktop computer that does not have wireless capability, and then you decide that you want to use a wireless connection to the Internet. What are the least expensive ways (choose two) to upgrade your system to wireless? a. Trade in the computer for another computer that has wireless installed. b. Purchase a second computer that has wireless capability. c. Purchase a wireless expansion card and install it in your system. d. Purchase a USB wireless adapter and connect it to the computer by way of a USB port.

Answers

Answer:

c. Purchase a wireless expansion card and install it in your system.

d. Purchase a USB wireless adapter and connect it to the computer by way of a USB port.

Explanation:

Assuming you purchased a new desktop computer that does not have wireless capability, and then you decide that you want to use a wireless connection to the Internet.

The least expensive ways to upgrade your system to wireless is to;

1. Purchase a wireless expansion card and install it in your system. The expansion card is a slot on the motherboard of a computer which allow users use an additional feature such as network, video, sound that may not be available before.

2. Purchase a USB wireless adapter and connect it to the computer by way of a USB port.

What type of operating system runs a dedicated electronic device such as a smart thermostat?

Answers

The type of operating system that runs a dedicated electronic device such as a smart thermostat is: embedded operating system.

What is an operating system?

An operating system (OS) can be defined as a system software that is typically pre-installed on a computing device, so as to manage (control) software application, computer hardware and user processes.

Types of operating system

There are different types of operating system (OS) and these include the following:

PC operating systemMobile operating systemNetwork operating systemEmbedded operating system

An embedded operating system is a specialized type of operating system (OS) that is typically designed and developed to be used in performing a specific task on an electronic device that is not a computer such as a smart thermostat.

Read more on computer here: https://brainly.com/question/959479

The type of operating system runs a dedicated electronic device such as a smart thermostat is An embedded operating system.

What is the  embedded operating system ?

An embedded operating system can be regarded as the specialized operating system (OS) which us been created to take up specific task for a device that is not a computer.

It is helps the device's hardware accessible to software.

Learn more about An embedded operating system at;https://brainly.com/question/14408927

Which kind of photography takes attractive photos of products to make them stand out?

Answers

Answer:

See there are multiple ways to get a perfect shot of products to stand out but the most affective according to me are explained below :-

Macro shooting - These are close shots u can say really close just to show the product more attractive and u can see these types of shots in every advertisement. Background shooting/shots - Opposite of macro shots. 3d shots - These are 360° shots.

Tip :- Use wide aperture like F2 and right aperture for right shots.

Hope it helps!

Select all of the uses of presentation software in the workplace.

to introduce a new project
to sell a product
to train employees
to store large amounts of data
to inspire people
to persuade management
to share information from a report
to call another employee across the country
to raise money for a cause

Answers

Answer:

uhm 1, 2, 3, 4, 6, 7, and 8.

Explanation:

because those are all the uses of presentation software in a workplace.

An author is preparing to send their book to a publisher as an email attachment. The file on their computer is 1000 bytes. When they attach the file to their email, it shows as 750 bytes. The author gets very upset because they are concerned that part of their book has been deleted by the email address. If you could talk to this author, how would you explain what is happening to their book?

Answers

Answer:

The data is transformed to usually make it smaller. It can always be re-constructed back to the original.

Explanation:

I'm on the same lesson on code.org as you, so just go to the question before and the answer to that question was the answer!  ;)

Let me know if you got it right!

In most cases, the information is altered to make it smaller. It's always possible to restore it to its original state.The fact that the attachment has shrunk in size does not imply that any elements of the book (i.e. the attachment) have been removed.It will also make it clear to him that the book's original size and content will be preserved after it is downloaded by the mail receiver.

Learn more:

brainly.com/question/1492433

Cryptanalysis is made more difficult by having shorter keywords.a) trueb) false

Answers

Answer:

B. False.

Explanation:

Cryptanalysis can be defined as the study, art or process of evaluating and analyzing information systems such as ciphertext, cryptographic systems and ciphers. The main purpose of Cryptanalysis is for a better understanding of how the cryptographic system works, in order to find techniques for deciphering, defeating or weakening them without an access to any privileged or secret data (information) required to do so.

Hence, cryptanalysis is made more difficult by having longer keywords as opposed to having shorter keywords which typically would make it easier for an attacker to decipher.

In a nutshell, it is false and incorrect to say that cryptanalysis is made more difficult by having shorter keywords.

which of the following is an example of libraries online?
A. iSEEK Education
B. DuckDuckGo
C. WorldCat
D. Ref Seek

Answers

I seek education is so hoped that helped

The one that is an example of libraries online is iSEEK education. The correct option is A.

What are online libraries?

A digital library, also known as an online library, an internet library, a digital repository, or a digital collection, is an online database of digital objects such as text, still images, audio, video, digital documents, or other digital media formats.

This means that students can consult online books, images, videos, and other educational content without having to wait for a physical library to open.

They can do it in a formal setting, such as school, or they can relax at home and get instant access to the information they require.

The benefits of a library management system include online and offline storage, automated backups, and simple upgrades that simplify and improve the learning process.

Thus, the correct option is A.

For more details regarding online libraries, visit:

https://brainly.com/question/6036261

#SPJ3

Write an expression that will cause the following code to print "I am a teenager" if the value of userAge is less than 20. Zybooks won't let me edit any other line, and UserAge > 20 was marked wrong. It won't accept the ≥ symbol either.

Answers

Answer:

Replace

if userAge > 20

with

userAge > 19

Explanation:

if userAge > 20  checks if age is 21, 22, 23, 24........

The else condition which prints "I am a teenager" checks if age is 20, 19, 18....

Notice that 20 is inclusive of the else condition; this shouldn't be because for userAge to be less than 20, 20 isn't inclusive

To solve this,

Replace if userAge > 20 with userAge > 19

So that, the else

The else condition which prints "I am a teenager" checks if age is 19, 18, 17, 16....

Which nmap switch is used to detect target OS and services?
a -S
b -p
c -F
d -A

Answers

Answer:

d -A

Explanation:

The -S switch is used to use a fake source address, and it can mask your ip.

The -p switch is used to indicate which ports you want to scan, because then it searches for all open ports it searches for that one specifically

The -F switch is used as the quick scan mode, scanning the surface

The -A switch is used to check the operating system.

List three things you would do if you were not forced to work.

Answers

Answer:

i would play with my friends and fish and watch movies

Explanation:

So, I have strict parents & need help, if u don’t know how to fix this after u read it, leave. I don’t want u getting points for nothing I’m deleting ur answer if u do it for points. Anyways, I want to get Spotify on my phone, but it says “Enter the password for (my email)”. How do I sign back into it if I don’t know the password. My dad has the password, but I don’t want to get in trouble for stealing his phone to fix mine. Please help, I’ll give the brainliest!

Answers

Well if you forgot your password you can click "Forgot Password" at the bottom and it should ask you some questions and send you an email with the password

You can click forget password and it will email a link to re-set your password. Or you can always ask someone to help you login.
Other Questions
Is the square root of 85 a rational number What does a strong text dependent response includes what do you need to do in order to develop more effective communication skills What do presentation and spreadsheet software have in common?a. Both analyze numeric data.b. Both calculate numeric formulas.c. Both convey numeric and/or text data.d. Both illustrate animations. Big Chungus gamingA: yesB: yesC: yesD: yes Solve for x in the equation x^2- 10x+ 25=35 GIVING BRAINLIEST Katie and Mina both commute to work. Katie's commute on the train takes 10 minutes more than one half as many minutes as Mina's commute by car. It takes Katie 30 minutes to get to work. Write an equation to determine how many minutes it takes Mina to get to work. 30 = one halfx + 10 30 = one halfx 10 30 = 2x 10 30 = 2x + 10 Simplify (4/5)^-2 . Show your work! Qu palabra completa la oracin lgicamente? the scale for a map to actual distance is 2 cm to a 100 miles the actual distance on the map be between Los Angeles and Las Vegas is 5.4 centimeters what is the actual distance in miles between Los Angeles and Las Vegas.Show your work. x: -2(x + 3) = -2(x + 1) - 4. ( 1 point) WILL GIVE BRAINLIST i need help Fate slew Him, but He did not drop She felled He did not fall Impaled Him on Her fiercest stakes He neutralized them all She stung Him sapped His firm Advance But when Her Worst was done And Heunmoved regarded Her Acknowledged Him a Man. What are three(3) poetic elements used in this poem? PLZ FAST"... (A)ll men are by nature equally free and independent, and have certain inherent rights... namely, the enjoyment of life and liberty, with the means of acquiring (getting) and possessing property...."- The Virginia Declaration of Rights, 1776This quote would later influence the creation of what document?A) Common Sense B) The U.S. Constitution C) Poor Richard's Almanac D) The Declaration of Independence Muscles work together as a system to help your body move while adding support true or false 10 times as many as 1 hundred is _____ hundreds are _____thousands. 20Simplify the expression:(6y + 4y + 7) (2y 10) The local humane society is restocking on cat food to prepare for kitten season. Very young kittens need kitten formula which costs $3.99 per bottle. Older kittens need wet cat food which costs $1.50 per can. Part A: Write an algebraic expression to describe how much the humane society will spend preparing for kitten season. Part B: How much money (before tax) will the humane society spend if they buy 30 bottles of kitten formula and 120 cans of wet cat food? Part C: If you add a 7% sales tax to the purchase of bottles of kitten formula and cans of wet cat food, write a new expression accounting for sales tax. Whats the rising action of once upon a time?? ANYONE.HELP!! what is the sum of a rational numbers?