On this assignment, efficiency concerns are more important than on previous assignments. For this reason, we have provided time limits for each question. To pass a test case, your program must produce the correct output (as always) but also finish within the time limit. Some solutions, while correct, may not be fast enough. Solving the problem with such a solution, though, is far from a waste of time: it has the possibility of receiving up to 70 percent of the points, it is a good step toward understanding how the problem can be solved, and it may help you progress to a faster solution! 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 o) elements from the start of a and then removing some (possibly o) 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 2 <1en (a) <= 500000 • 1 <= a[i] <= 10**9 Your Sample Input 1 program must finish running on any valid input within 3 seconds. 10 6 9 1 3 Sample Output 1 Sample 1 Explanation • If Michael selects all of the problems, the maximum difficulty would be 10 and the minimum difficulty would be 1. In this case, the difference he wants to minimize would be 9. • If he selects the sublist 69, the maximum and minimum difficulties would be 9 and 6 respectively and the difference would be 3. • Note that he can't select 10 9, as that's not a sublist of a. Sample Input 2 0 777 Sample Output 2

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

Pls see attached

On this assignment, efficiency concerns are more important than on previous
assignments. For this reason, we have provided time limits for each question. To
pass a test case, your program must produce the correct output (as always) but
also finish within the time limit. Some solutions, while correct, may not be fast
enough. Solving the problem with such a solution, though, is far from a waste of
time: it has the possibility of receiving up to 70 percent of the points, it is a good
step toward understanding how the problem can be solved, and it may help you
progress to a faster solution!
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 o) elements from the start of a and then removing some (possibly o)
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
• 2 <= 1en (a) <= 500000
• 1 <= a[i] <= 10**9
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
• If Michael selects all of the problems, the maximum difficulty would be 10
and the minimum difficulty would be 1. In this case, the difference he wants
to minimize would be 9.
• If he selects the sublist 6 9, the maximum and minimum difficulties would be
and 6 respectively and the difference would be 3.
9
• Note that he can't select 10 9, as that's not a sublist of a.
Sample Input 2
777
Sample Output 2
0
Transcribed Image Text:On this assignment, efficiency concerns are more important than on previous assignments. For this reason, we have provided time limits for each question. To pass a test case, your program must produce the correct output (as always) but also finish within the time limit. Some solutions, while correct, may not be fast enough. Solving the problem with such a solution, though, is far from a waste of time: it has the possibility of receiving up to 70 percent of the points, it is a good step toward understanding how the problem can be solved, and it may help you progress to a faster solution! 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 o) elements from the start of a and then removing some (possibly o) 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 • 2 <= 1en (a) <= 500000 • 1 <= a[i] <= 10**9 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 • If Michael selects all of the problems, the maximum difficulty would be 10 and the minimum difficulty would be 1. In this case, the difference he wants to minimize would be 9. • If he selects the sublist 6 9, the maximum and minimum difficulties would be and 6 respectively and the difference would be 3. 9 • Note that he can't select 10 9, as that's not a sublist of a. Sample Input 2 777 Sample Output 2 0
Expert Solution
steps

Step by step

Solved in 4 steps with 3 images

Blurred answer
Knowledge Booster
Bare Bones Programming Language
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education