Selection proof: Positive proof strip
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. - Create a list
positiveValuesthat keeps only the numbers insubsetTotalsthat are greater than 0, in the same order. - Complete
selectionProofPositiveProofStripso it returnspositiveValues. Return it, do not print it.
Example
If readings is [12, 7, 7, 7, -4], then subsetTotals is [-4, 0, 3, 7, 8, 10, 12, 14, 15, 17, 19, 21, 22, 26, 29, 33] and selectionProofPositiveProofStrip returns [3, 7, 8, 10, 12, 14, 15, 17, 19, 21, 22, 26, 29, 33].
Rules
- If no number is greater than 0, return [].
Test data
TEST DATA 1: readings is [2, -6, 2, 0, 7].
TEST DATA 2: readings is [5, -6, 5, 5].
Examples
Input: readings = [2,-6,2,0,7] Output: [1,2,3,4,5,7,9,11]
subsetTotals is [-6, -4, -2, 0, 1, 2, 3, 4, 5, 7, 9, 11]. Keep only numbers greater than 0, without changing their order. Return [1, 2, 3, 4, 5, 7, 9, 11].
Input: readings = [5,-6,5,5] Output: [4,5,9,10,15]
subsetTotals is [-6, -1, 0, 4, 5, 9, 10, 15]. Keep only numbers greater than 0, without changing their order. Return [4, 5, 9, 10, 15].
Input: readings = [] Output: []
subsetTotals is [0]. Keep only numbers greater than 0, without changing their order. Return [].
Input limits
- 0 <= input size <= 10.
- 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.