Question: 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

Array Journey You are standing at the start of an array of

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

1 Expert Approved Answer
Step: 1 Unlock

mainpy 1 2 3 4 5 6 7 8 9 125 10 11 3 10 20 5 def journey n p... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Electrical Engineering Questions!