Math Homework
You are given a sorted array points representing the point values of homework problems in the order they appear.
A student must solve the first problem at index 0. After solving a problem at index i, the student may solve either the next problem i + 1 or skip one problem and solve i + 2.
The student continues until the difference between the maximum and minimum point values among the solved problems is at least threshold. If that can never be achieved, the student must solve all problems.
Return the minimum number of problems the student needs to solve.
Complete the function minProblemsToSolve in the editor below.
minProblemsToSolve has the following parameters:
int[] points: sorted point values for the homework problemsint threshold: the required spread between the minimum and maximum solved point values
Returns
int: the minimum number of problems that must be solved
1Example 1
1, 3, and 8. The solved values have spread 8 - 1 = 7, and it takes only 3 problems.2Example 2
1, 3, and 5. The spread is exactly 4, so the answer is 3.3Example 3
7 - 4 = 3, so the student must solve all 4 problems.Constraints
Limits and guarantees your solution can rely on.
pointsis sorted in non-decreasing order.1 ≤ points[i] < 1000.1 ≤ threshold < 1000.