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]
Lecture
AI Tutor
Design
Upload
Notes
Favorites
Help