Selection proof: Threshold file
Inputs
readings is a list of integers (numbers with no decimal part). It may be empty, and numbers may repeat unless task 1 says otherwise.
Your tasks
- Create a list
subsetTotals. Choose any positions fromreadings, or choose none. Add the numbers at those positions. List every different total you can make, from smallest to largest. Choosing no positions gives a total of 0. Each position can be chosen at most once. Equal numbers at different positions are separate choices, but each total appears only once insubsetTotals. - Count the numbers in
subsetTotalsthat are at leastk(greater than or equal tok). Store the count inatLeastK. - Complete
selectionProofThresholdFileso it returnsatLeastK. Return it, do not print it.
Example
If readings is [8, 8, -9, 2, 5] and k is 7, then subsetTotals is [-9, -7, -4, -2, -1, 0, 1, 2, 4, 5, 6, 7, 8, 9, 10, 12, 13, 14, 15, 16, 18, 21, 23] and selectionProofThresholdFile returns 12.
Rules
k(a whole number from 1 to 8) is the threshold in task 2: compare each number with it.
Test data
TEST DATA 1: readings is [0, 8, 18, -12, 8] and k is 1.
TEST DATA 2: readings is [2, 2, -4, 2] and k is 5.
Examples
Input: readings = [0,8,18,-12,8] k = 1 Output: 9
subsetTotals is [-12, -4, 0, 4, 6, 8, 14, 16, 18, 22, 26, 34]. Here k is 1. The numbers at least 1 are [4, 6, 8, 14, 16, 18, 22, 26, 34]. There are 9, so return 9.
Input: readings = [2,2,-4,2] k = 5 Output: 1
subsetTotals is [-4, -2, 0, 2, 4, 6]. Here k is 5. The numbers at least 5 are [6]. There are 1, so return 1.
Input: readings = [] k = 7 Output: 0
subsetTotals is [0]. Here k is 7. The numbers at least 7 are []. There are 0, so return 0.
Input limits
- 0 <= input size <= 10.
- k is a whole number from 1 to 8. Answers fit in a signed 32-bit integer: -2,147,483,648 through 2,147,483,647.
- Input numbers have no decimal part. They range from -1,000,000 to 1,000,000. Follow any extra input rules in task 1.
Efficiency goal
Big-O describes how the work or memory needed grows as the input gets larger.
Efficiency goal: time O(n*2^n); extra memory, including the helper list, O(2^n). n is the input length. These labels describe how work and memory grow with the input.
Practice focus
Build subsetTotals first, then return exactly what the tasks ask for. Follow the order, keep repeated values when the rule says so, and check the empty case.