Selection proof: 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. - Complete
selectionProofProofStripso it returnssubsetTotals. Return it, do not print it.
Example
If readings is [4, -6, 0, 6, 6], then subsetTotals is [-6, -2, 0, 4, 6, 10, 12, 16] and selectionProofProofStrip returns [-6, -2, 0, 4, 6, 10, 12, 16].
Test data
TEST DATA 1: readings is [7, 7, 0, -6, 9].
TEST DATA 2: readings is [4, 4, -5, 4].
Examples
Input: readings = [7,7,0,-6,9] Output: [-6,0,1,3,7,8,9,10,14,16,17,23]
subsetTotals is [-6, 0, 1, 3, 7, 8, 9, 10, 14, 16, 17, 23]. selectionProofProofStrip returns that whole list, so return [-6, 0, 1, 3, 7, 8, 9, 10, 14, 16, 17, 23].
Input: readings = [4,4,-5,4] Output: [-5,-1,0,3,4,7,8,12]
subsetTotals is [-5, -1, 0, 3, 4, 7, 8, 12]. selectionProofProofStrip returns that whole list, so return [-5, -1, 0, 3, 4, 7, 8, 12].
Input: readings = [] Output: [0]
subsetTotals is [0]. selectionProofProofStrip returns that whole list, so return [0].
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.