Minimal Absolute Difference
There are N pyramids in a line.You are given their heights as a list of integers.Write a program to find the minimum absolute difference between the heights of any two different pyramids.
Input
The input is a single line containing space-separated integers.
Output
The output should be a single line containing the minimum absolute difference of any two different pyramid heights.
Explanation
Given Pyramid heights are 7 1 5.
The absolute difference between the heights of any two different pyramids are
line = input()
L = [int(s) for s in line.split()]
n = len(L)
max_diff = 0
for i in range(n-1):
for j in range(i+1, n):
diff = abs(L[i] - L[j])
if diff > max_diff:
max_diff = diff
print('Given Pyramid heights are', end=' ')
for i in range(n):
print(L[i], end=' ')
print()
print('The absolute difference between the heights of any two different pyramids are',
max_diff)
Comments
Leave a comment