Positive trays: 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
kept. Keep only numbers greater than 0 fromreadings. Put them inkeptin their original order. Keep repeated numbers. Leave out 0 and negative numbers. - Create a list
positiveValuesthat keeps only the numbers inkeptthat are greater than 0, in the same order. - Complete
positiveTraysPositiveProofStripso it returnspositiveValues. Return it, do not print it.
Example
If readings is [2, 6, 5, 5, -8], then kept is [2, 6, 5, 5] and positiveTraysPositiveProofStrip returns [2, 6, 5, 5].
Rules
- Keep repeated numbers.
- If
keptis empty, return [].
Test data
TEST DATA 1: readings is [4, -12, 0, 7, 7].
TEST DATA 2: readings is [8, 8, -9, 8].
Examples
Input: readings = [4,-12,0,7,7] Output: [4,7,7]
kept is [4, 7, 7]. Keep only numbers greater than 0, without changing their order. Return [4, 7, 7].
Input: readings = [8,8,-9,8] Output: [8,8,8]
kept is [8, 8, 8]. Keep only numbers greater than 0, without changing their order. Return [8, 8, 8].
Input: readings = [] Output: []
kept is []. Keep only numbers greater than 0, without changing their order. Return [].
Input limits
- 0 <= input size <= 64.
- 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); extra memory, including the helper list, O(n). n is the input length. These labels describe how work and memory grow with the input.
Practice focus
Build kept 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.