Windy weather#5713

Windy weather (Editorial)

Among the given grass blade heights, find the smallest value and the largest value . The difference max - min will determine the wind's strength according to Piglet.

Algorithm implementation

Read the number of grass blades .

scanf("%d",&n);

Initialize the variables and .

min_el = INT_MAX;
max_el = INT_MIN;

Read the heights of grass blades. For each height, update the minimum and maximum values.

for (i = 0; i < n; i++)
{
  scanf("%d", &x);
  if (x > max_el) max_el = x;
  if (x < min_el) min_el = x;
}

Print the wind’s strength according to Piglet's definition.

printf("%d\n",max_el - min_el);

Python implementation

Read the input data.

n = int(input())
lst = list(map(int,input().split()))

Print the wind's strength according to Piglet's definition.

print(max(lst) - min(lst))