AMAZON Coding Question – Solved

5 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

| You are given a board of size M Γ— N where each cell can be either empty ('O') o… |
| Undirected Coloured Graph Shortest Path You are given an undirected weight… |
| Village Voyage A computer game "Village Voyage" has N villages (labeled 1 to… |
| Academic Decathlon Students are being selected for an academic decathlon tea… |
| Sum of Arrays Given two arrays each of length n, arr1 and arr2, in one opera… |
| Count Swaps During Custom Sorting Analyze the efficiency of the following so… |