Coding Quiz - List of Integers with Sum Greater than Target
In this coding quiz, you will write a function that uses a stack to return a list of integers with a sum greater than a given target value (target).
You will receive input from the user: a target value and a list of integers. You need to push consecutive integers onto the stack until their sum exceeds the target.
Then, return a list containing all the integers currently in the stack that have a sum greater than the target.
def solution(target, numbers): # Write your code here return
Constraints
-
The
targetreceived as input must be a positive integer. -
The input list must consist solely of integers and its length must be at least 1.
-
The sum of all integers in the returned list must be greater than
target.
Input and Output Examples
-
Input:
target = 15,numbers = [1, 2, 3, 5, 7, 8] -
Output:
[1, 2, 3, 5, 7]
-
Input:
target = 8,numbers = [2, 3, 1, 2, 4, 3] -
Output:
[2, 3, 1, 2, 4]
Lessons in this chapter · Practice with Common Coding Quiz Types
- 1. Coding Quiz - Finding Rotten Apples
- 2. Finding Rotten Apples Explained
- 3. Coding Quiz - Calculating the Sum of a List Recursively
- 4. Explanation for Recursively Calculating the Sum of a List
- 5. Coding Quiz - 1, 2, 3 Addition
- 6. Explanation for Adding 1, 2, 3
- 7. Coding Quiz - Flattening a 2D Array
- 8. Converting to a 1D Array Explanation
- 9. Coding Quiz - Calculate the Sum of a List Using Divide and Conquer
- 10. Explanation of Calculating the Sum of a List Using Divide and Conquer
- 11. Coding Quiz - Gym Uniform Problem
- 12. Gym Uniform Problem Explanation
- 13. Coding Quiz - List of Integers with Sum Greater than Target
- 14. Explanation of Integer List with Sum Greater Than Target
- 15. Coding Quiz - Finding Travel Routes
- 16. Finding Travel Itinerary Explanation
Lecture
AI Tutor
Design
Upload
Notes
Favorites
Help