AMAZON Coding Question – Solved

9 Live
A user is using the Amazon fitness tracker and is engaged in a jumping exercise routine. The user is positioned on the ground, and there are n blocks, each placed at different heights. The height of the ith block is represented by height[i] feet. The goal is to maximize the calorie burn during this exercise. The calories burned when jumping from the ith block to the jth block is calculated as (height[i] - height[j])Β². The user intends to jump on each block exactly once but can choose the order in which they jump. Since the user wants to optimize calorie burn for this session, the task is to determine the **maximum amount of calories** that can be burned during the exercise. Notes: - The user can jump from any block to any block. - The ground's height is 0. - Once the user jumps from the ground to a block, they **cannot** go back to the ground. Example: n = 3 height = [5, 2, 5] The user can jump in this sequence: Ground β†’ 3rd block β†’ 2nd block β†’ 1st block Calories burned: (0 - 5)Β² + (5 - 2)Β² + (2 - 5)Β² = 25 + 9 + 9 = 43 It can be shown that no other order results in more than 43 units of calorie burn. Hence, the answer is 43. Function Description: Complete the function `optimizeCalorieBurn` in the editor below. Function Signature: `int optimizeCalorieBurn(int[] height)`

Asked in: AMAZON

Image of the Question

Question Image Question Image Question Image

All Testcases Passed βœ”



Passcode Image

Solution


Please login to view the solution


Related Questions

| Amazon has multiple delivery centers for the distribution of its goods. In one … |
| Amazon Kindle has several e-books that customers can purchase directly. There a… |
| The engineering team at an Amazon fulfillment center is optimizing n high-perfo… |
| The supply chain manager at one of Amazon's warehouses is shipping the last con… |
| Determine the highest value after executing n steps on an infinite 2D grid that… |
| Amazon Prime Video is developing a new feature called "Segmentify." This featur… |