Building an exam paper
Statement
A problem setter wants to set N problems. Given the difficulty of each of the N problems, the setter wants to use all N problems to build a single exam paper.
The setter does not want the difficulty to rise or fall sharply as a test taker works through the paper. So when setting the problems, the goal is to minimize the largest difficulty gap between two adjacent problems. Some test takers will work through the problems backwards, and some will start from the middle. For that reason problem 1 and problem N also count as adjacent.
Given the difficulty of each of the N problems, write a program that computes the minimum possible value of the largest difficulty gap between two adjacent problems. For example, suppose N=5 and the difficulties are given as [1, 5, 3, 9, 2]. In that case, if the problems are arranged as [1, 3, 9, 5, 2], the largest difficulty gap between two adjacent problems is 6.
Input and Output Examples
Example 1
Input
5, [1, 5, 3, 9, 2]
Output
6
Example 2
Input
7, [1, 5, 7, 2, 4, 6, 3]
Output
2
Input
First the number of problems N is given. N is an odd natural number less than or equal to 100,000.
Next an array arr holding the difficulty of each problem is given. Each difficulty is a natural number from 1 to 100,000.
Output
Given the difficulty of each of the N problems, return the minimum possible value of the largest difficulty gap between two adjacent problems.
Requirements
- You must write a solution(N, arr) 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 18 cases, and 2 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 18 cases to solve this.
Examples
2 public cases. Judging also uses hidden cases. You have to pass all 18 cases to solve this.
5, [1, 5, 3, 9, 2]
6
7, [1, 5, 7, 2, 4, 6, 3]
2
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 2 of practice test 2 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.
Submitting requires you to log in. Running against the public cases works without one.
You can test with 2 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.
Input read time 125ms (excluded from the ranking)
Log in and you can see the code once you solve this problem.