0

Given an array , the task is to find the array formed from the difference of each element from the largest element in the given

Given an array , the task is to find the array formed from the difference of each element from the largest element in the given array. Input: {3, 6, 9, 2,6} Output: {6, 3, 0, 7, 3} Explanation: Largest element of the array = 9 Therefore difference of arr[i] from 9: Element 1: 9 – 3 = 6 Element 2: 9 – 6 = 3 Element 3: 9 – 9 = 0 Element 4: 9 – 2 = 7 Element 5: 9 – 6 = 3 Hence the output will be {6, 3, 0, 7, 3} Input: {7, 2, 5, 6, 3, 1, 6, 9} Output: {2, 7, 4, 3, 6, 8, 3, 0}

13th Feb 2020, 4:22 PM
Aslam Basha
Aslam Basha - avatar
1 Respuesta
+ 1
The simplest program code is as follows: numbers = list(map(int, input().split(','))) max_number = max(numbers) f = lambda x: max_number - x numbers = list(map(f, numbers)) print(numbers) Input: 7, 2, 5, 6, 3, 1, 6, 9 Output: [2, 7, 4, 3, 6, 8, 3, 0]
28th Jun 2021, 9:15 AM
Obloev Komronbek
Obloev Komronbek - avatar