Do in C++ or Python Array Journey You are standing at the start of an array of
Fantastic news! We've Found the answer you've been seeking!
Question:
Do in C++ or Python
Transcribed Image Text:
✩ 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 1≤n≤105 ● < 0 ≤ \path[i] ≤ 105, where 0 ≤i<n and |x| denotes absolute value of x. 1≤k≤n ► Input Format for Custom Testing ▾ Sample Case 0 Sample Input 0 3 10 -20 -5 2 Sample Output 0 5 ✩ 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 1≤n≤105 ● < 0 ≤ \path[i] ≤ 105, where 0 ≤i<n and |x| denotes absolute value of x. 1≤k≤n ► Input Format for Custom Testing ▾ Sample Case 0 Sample Input 0 3 10 -20 -5 2 Sample Output 0 5
Expert Answer:
Answer rating: 100% (QA)
mainpy 1 2 3 4 5 6 7 8 9 125 10 11 3 10 20 5 def journey n p... View the full answer
Related Book For
Fundamentals of Financial Management
ISBN: 978-1305635937
Concise 9th Edition
Authors: Eugene F. Brigham
Posted Date:
Students also viewed these electrical engineering questions
-
c or c++ or Java or python 2. Dam Design Your company is designing a dam to be built across a stream to create a small lake. To reduce materials cost, it will be made of one or more concrete walls...
-
: Write code in the next cell to do the following: 1. Asks the user for their first, middle, and last names and stores each in a new variable. 2. Computes the length of the name not including spaces...
-
Do you prefer email or SMS for certain activities? Please explain.
-
Why does the following code fragment not have the same effect as the code fragment in the previous question? x.next t.next = t; = x.next;
-
1. What external factors were affecting UPSs HR practices? How did UPS respond to these trends? 2. Why is efficiency and safety so important to UPS? What role do the companys industrial engineers...
-
A jeweler is examining a diamond 5.0 mm in diameter with a loupe having a focal length of 25.4 mm. (a) Determine the maximum angular magnification of the loupe. (b) How big does the stone appear...
-
Which of the following is not an element of an internal control system? a. Auditing b. The control environment C. Monitoring d. Information and communication
-
Suppose Procter & Gamble (P&G) learns that a relatively new startup company Method (www. methodhome.com) is gaining market share with a new laundry detergent in West Coast markets. In response, P&G...
-
Case 11-2: McMichael Inc. Art Flynn, packaging buyer for McMichael Inc. (MI), was working on an import substitution project involving a local minority supplier. He was concerned, however, that his...
-
Luna Company is an IFRS reporter. Luna Company acquired 100% of the voting stock of the AutoMania Group on January 1 of the current year for a total acquisition cost of $251,000. The trial balance of...
-
Why did Prolog respond to the last goal as it did? Is Prolog saying that there are no X that are not human, that is, that all X are human? Why?|| Given only the following Prolog clause: human (bob)...
-
How much discount interest will there be if 8 2 , 5 0 0 is due at the end of 4 . 5 years with 1 0 . 9 % interest rate
-
CALCULATE THE INITIAL COSTS, CALCULATE THE OPERATING CASH FLOW, CALCULATE THE TERMINAL NON OPERATING CASH FLOW, CALCULATE THE NPV . Initial Equipment $ 6 5 , 0 0 0 Project Life 3 Years Sales$ 5 5 ,...
-
A start-up has been approached by a Venture Capital investor, who would like to invest $700,000 into the business. The start-up's CEO is preparing for the term sheet negotiations, and wants to know...
-
Outback Outfitters sells recreational equipment. One of the company s products, a small camp stove, sells for $ 1 4 0 per unit. Variable expenses are $ 9 8 per stove, and fixed expenses associated...
-
Rowland & Sons Air Transport Service, Incorporated, has been in operation for three years. The following transactions occurred in February: February 1 Paid $ 5 5 5 to rent equipment that was used and...
-
Calculate the degree of freedom for the mechanisms shown in Figure 1 below. 4 1P D 2 i p 4 4 7 5 6 3 5 6 S 9 10 F 5 6 Figure 1 E 11 13 12 4 1 14 D B 3 2 C
-
Q:1 Take any product or service offered in Pakistan and apply all determinents of customer Perceived value ?
-
Interest rates on 4-year Treasury securities are currently 6.7%, while 6-year Treasury securities yield 7.25%. If the pure expectations theory is correct, what does the market believe that 2-year...
-
Brandtly Industries invests a large sum of money in R&D; as a result, it retains and reinvests all of its earnings. In other words, Brandtly does not pay any dividends, and it has no plans to pay...
-
Bank A pays 2% interest compounded annually on deposits, while Bank B pays 1.75% compounded daily. a. Based on the EAR (or EFF%), which bank should you use? b. Could your choice of banks be...
-
Founded in 1998, PAETEC Communications is a broadband telecommunications firm providing local and long-distance voice, data, and Internet services to business customers in over 80 markets in the...
-
In organizations like Merck & Co., the pharmaceuticals giant, and Microsoft Corporation, the leading producer of computer software, research scientists or computer programmers often work together in...
-
In 1994, Jeffrey Bezos, a computer science and electrical engineering graduate from Princeton University, was growing weary of working for a Wall Street investment bank. His computer science...
Study smarter with the SolutionInn App