Log inSign up
Problems / A019

The gap

100 ptsCases 17Set by dongbinna
Added October 30.
1 solved1 attempted1 submissionssolvers took 1.0 tries on average

Statement

There is a game, and playing it gives you a score as the result. N students played the game and each earned a score. Each score a student earned is a natural number from 1 to 10,000,000.

We want to know how big the overall gap in skill is among the N students who played the game. So, as a measure of that gap, write a program that returns the difference between the largest and the smallest of all the scores the students earned.

Input and Output Examples

Example 1

Input

8, [7, 7, 5, 8, 9, 4, 6, 2]

Output

7

Example 2

Input

10, [5, 3, 7, 5, 3, 3, 6, 1, 8, 7]

Output

7

Example 3

Input

12, [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]

Output

11

Example 4

Input

2, [5, 5]

Output

0

Input

  • First the number of students N is given as a natural number. N is a natural number greater than or equal to 2 and less than or equal to 100,000.

  • Next an array scores is given, holding the score of each student numbered 1 through N. Each score value is a natural number less than or equal to 10,000,000.

Output

  • Return the difference between the largest and the smallest of all the scores the students earned.

Requirements

  • You must write a solution(N, scores) function and return the answer
  • Trailing spaces at the end of a line and blank lines at the end of the output are ignored when grading
  • The languages you can use are Python and JavaScript
  • The memory limit is 256MB. The browser does not measure it, it only states it
  • The time limit is set by measuring the setter's reference solution on the same runtime
  • On this problem you submit code, not a prompt. That code runs in the browser on this device, and all that goes to the server is a fingerprint of the output and the time it took. Whether it is correct is decided by the server. The run time is a number each device reports, so the code and the device details are posted next to it on the leaderboard.
  • The output has to match the expected value down to the character. A space inside a line counts the same as any other character.
  • There are 17 cases, and 4 of them show the input together with the expected output. The rest are used only when you submit and are not shown on this page.
  • You have to pass all 17 cases to solve this.
Read the requirements carefully before solving. Tampering with the grading to make a submission look like a pass can get you sanctioned if caught. The code you submit is published on the leaderboard along with the result.

Examples

4 public cases. Judging also uses hidden cases. You have to pass all 17 cases to solve this.

Input
Expected output
8, [7, 7, 5, 8, 9, 4, 6, 2]
7
10, [5, 3, 7, 5, 3, 3, 6, 1, 8, 7]
7
12, [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]
11
2, [5, 5]
0

Notes

Background that helps with solving. The rules you have to follow are in the input and output specs and the requirements above.

This is problem 7 of practice test 1 in the original.

Solution

Your code runs on this device. Only the fingerprint of the output and the elapsed time go to the server. The server decides whether it is correct.

0 chars1 lineMemory 256MB (recorded only)Reference 4.0ms

Submitting requires you to log in. Running against the public cases works without one.

You can test with 4 public cases. Submitting runs the hidden cases too.

People who solved this problem

The time shown is the time spent solving. Input reading time is outside the solver's control, so it is excluded. And since each device reports this value itself, we record which device measured it.

1bampal234ms62 charsPythonWindows NT 10.0 / Chrome/156.0.0.0 / 8코어 / 16GB

Input read time 125ms (excluded from the ranking)

This person kept their code private.