Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Saitama is a superhero. His power is jumping from one building to another. His jumping power is magical: if he jumps on a certain building

Saitama is a superhero. His power is jumping from one building to another. His jumping power is magical: if he jumps on a certain building (to save the people living in this building) he is not allowed to jump on the adjacent building, i.e. if he jumps on building i, he has to skip building i+1.If the number of buildings in the city is N, and we know for each building the number of people living in that building and given that a huge fire erupts in the city and all the buildings are burning, return the maximum number of people Saitama can save by jumping from one building to another (unfortunately he cannot save them all!). Consider that all the buildings in the city form one long array, Saitama starts jumping from one side of the array till the end of the array. Frogman can jump to any building he wants (as long as he respects the magical restriction mentioned above), however, once he jumps to a building, he can only jump forward but not backwards.Input FormatN (total number of buildings in the city)p1 p2... pN (people living in each building)ConstraintsAll integersOutput FormatZ (maximum number of people that can be saved by Saitama)Sample Input 042342Sample Output 06Explanation 0Best scenario would be: Jumping on building 1(saved 2 people) and then jump on building 3(save 4 people). Max total number Saitama can save =2+4=6. One other possible (but not optimal) scenario is if he first jumps to building 2(saves 3 people) then jump to building 4(saves 2 people), so the total would be 3+2=5.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Oracle 10g SQL

Authors: Joan Casteel, Lannes Morris Murphy

1st Edition

141883629X, 9781418836290

More Books

Students also viewed these Databases questions

Question

4-31. We will be opening our new facility sometime this spring.

Answered: 1 week ago