Fill This Form To Receive Instant Help
Homework answers / question archive / You should use the time limits and constraints to figure out the kind of efficiency class that will pass all test cases in time
Q1: Assignment Difficulty
Dan has a list of problems suitable for Assignment 4. The difficulties of these problems are stored in a list of integers a. The i-th problem's difficulty is represented by a[i] (the higher the integer, the more difficult the problem).
Dan is too busy eating saltines to worry about Assignment 4 decisions, so he asks Michael the TA to select at least two problems from the list for the assignment. Since there are many possible subsets of the problems to consider and Michael has a life, he decides to consider only sublists (definition follows) of the list of problems.
To make grading the assignment easier, Michael wants to pick problems that don't vary too much in difficulty. What is the smallest difference between the difficulties of the most difficult selected problem and the least difficult selected problem he can achieve by selecting a sublist of length at least 2 of the original list of problems?
Definition: A sublist of a list a is any list you can obtain by removing some (possibly 0) elements from the start of a and then removing some (possibly 0) elements from the end of it. (It's like the definition of segment from lecture.) .
Filename
Your filename for this question must be q1.py.
Input
The input consists of a single line containing the integers in the list a, separated by single spaces.
Output
Print a single integer indicating the smallest difference in difficulties Michael can achieve.
Constraints
Time Limit
Your program must finish running on any valid input within 3 seconds.
Sample Input 1
10 6 9 1
Sample Output 1
3
Sample 1 Explanation
Sample Input 2
7 7 7
Sample Output 2
0