Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Do in C++ or Python Array Journey You are standing at the start of an array of integers. You want to move to the end

Do in C++ or Python

image

Array Journey You are standing at the start of an array of integers. You want to move to the end of the array, collecting as many points as possible along the way. Each step can cover a maximum number of elements. Each time you land on an element, its value is added to your score. What is the maximum score achievable? For example, you are at position 0 of the array path = [10, 2, -10, 5, 20]. Your maximum step can cover k=2 elements. Your score starts at 10, the value at index 0. Your first step could land you on elements valued 2 or -10. You choose to land on 2 to achieve the higher score, now 10+2=12. Next you choose between landing on -10 or 5. You choose 5 for a score of 12+5=17. You make one final move to your goal and your total score is 17+20=37. Function Description Complete the function journey in the editor below. The function must return a long integer denoting your maximum attainable score. journey has the following parameter(s): path[path[0],...path[n-1]]: an array of integers k: an integer, the maximum step length Constraints 1n105 < 0 \path[i] 105, where 0 i

Step by Step Solution

3.46 Rating (153 Votes )

There are 3 Steps involved in it

Step: 1

mainpy 1 2 3 4 5 6 7 8 9 125 10 11 3 10 20 5 def journey n p... 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

Fundamentals of Financial Management

Authors: Eugene F. Brigham

Concise 9th Edition

1305635937, 1305635930, 978-1305635937

More Books

Students also viewed these Electrical Engineering questions

Question

Do you prefer email or SMS for certain activities? Please explain.

Answered: 1 week ago