Skip to content

ORIGINAL CODING QUESTION

Interview score spread

A hiring panel recorded n interview scores for one candidate pool. Report the spread: the highest score minus the lowest score. With a single score the spread is 0.

Open practice workspace

Original exercise · easy. Editorial role relevance does not imply a company has asked this question.

Input and output

First integer n, then n integers. Print one integer.

Constraints

1 ≤ n ≤ 200; -1000 ≤ score ≤ 1000.

Example 1

Input

5
72 85 60 91 78

Output

31

The highest score is 91 and the lowest is 60, so the spread is 31.

Example 2

Input

3
-4 -4 -4

Output

0

All scores are equal, so the spread is 0.

Explain your approach

Explain your time and auxiliary space complexity. Which input makes your algorithm work hardest?

Private grading inputs, expected outputs and canonical reference implementations are withheld. Authored expected outputs were cross-checked with independent reference oracles; compiler/runtime behavior still needs a verified execution provider.

Hint 1

You only need two numbers from the whole list.

Hint 2

Track the smallest and largest score seen so far in one pass.

Hint 3

Start both trackers at the first score, update them for every later score, and return largest minus smallest.

Practice this question

Save your work privately, explain decisions and return to your revision queue.

Open practice workspaceBrowse the question library →