CST Training assignment 13 solved

$30.00

Category: You will Instantly receive a download link for .zip solution file upon Payment || To Order Original Work Click Custom Order?

Description

5/5 - (5 votes)

Assignment
Question-1
Given an integer K and an array of integers arr, the task is to find the maximum element from the array and
after every retrieval the number will get decremented by 1. Repeat these steps exactly K number of times
and print the sum of all the values retrieved in the end.
Input: K = 3, arr[] = {2, 3, 5, 4}
Output: 13
For K = 1, current maximum is 5 (Sum = 5 and arr[] = {2, 3, 4, 4})
For K = 2, current maximum is 4 (Sum = 5 + 4 = 9 and arr[] = {2, 3, 3, 4})
For K = 3, current maximum is 4 (Sum = 9 + 4 = 13 and arr[] = {2, 3, 3, 3})
Hence, the result is 13
Question-2
Given an array a, your task is to convert it into a non-increasing form such that we can either increment or
decrement the array value by 1 in minimum changes possible.
Input : a[] = {3, 1, 5, 1}
Output : 4
We need to decrease 5 to 1 to make array sorted
in non-increasing order.
Input : a[] = {1, 5, 5, 5}
Output : 4
We need to increase 1 to 5.