Largest Possible Difference
Coding Problem Keys
Largest Possible Difference
Problem Statement
There are N positive integers passed as the input. The program must print the largest possible differences between N/2 pairs in the descending order as the output.
Boundary Condition(S)
2 <= N <= 50
1 <= Each integer value <= 1000
Input Format
The first line contains N.
The second line contains N integers separated by a space.
Output Format
The first line contains the largest possible difference between N/2 pairs in the descending order.
Example Input/Output 1
Input
5
100 50 12 60 55
Output
88 10
Explanation
The largest difference is possible for 100-12.
Now the remaining values are 50 60 55.
Now the largest possible difference is 60-50.
Example Input/Output 2
Input
6
10 20 30 40 50 60
Output
50 30 10
Example Input/Output 3
Input
3
77 98 53
Output
45
Note: Max Execution Time Limit: 500 millisecs
Solution
Programming Language: Python 3 Language
n=int(input())
l=list(map(int,input().split()))
while(len(l)>1):
print(max(l)-min(l),end=" ")
l.remove(max(l))
l.remove(min(l))
# Published By PKJCODERS
(Note: Incase If the code doesn't Pass the output kindly comment us with your feedback to help us improvise.)
Comments