Selection proof: Total receipt
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. - Add up every number in
subsetTotals. Store the sum intotal. - Complete
selectionProofTotalReceiptso it returnstotal. Return it, do not print it.
Example
If readings is [-9, 8, 5, 5, 0], then subsetTotals is [-9, -4, -1, 0, 1, 4, 5, 8, 9, 10, 13, 18] and selectionProofTotalReceipt returns 54.
Test data
TEST DATA 1: readings is [-2, 17, 3, 0, 17].
TEST DATA 2: readings is [4, 4, -1, 4].
Examples
Input: readings = [-2,17,3,0,17] Output: 210
subsetTotals is [-2, 0, 1, 3, 15, 17, 18, 20, 32, 34, 35, 37]. Add its numbers to get 210. Return 210.
Input: readings = [4,4,-1,4] Output: 44
subsetTotals is [-1, 0, 3, 4, 7, 8, 11, 12]. Add its numbers to get 44. Return 44.
Input: readings = [] Output: 0
subsetTotals is [0]. Add its numbers to get 0. 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.