Skip to main content
Practice

coding-quiz-7

---
id: coding-quiz-7
title: Coding Quiz - List of Integers with Sum Greater than Target
description: Write a function that returns a list of integers with a sum greater than a given target using a stack.
tags:
- Python
- Stack
- Algorithm
- Function
sidebar_position: 13
isPublic: false
---

# 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`.

<br />

```python title="Write Code"
def solution(target, numbers):
# Write your code here
return



Constraints

  • The target received 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]

Want to learn more?

Join CodeFriends Plus membership or enroll in a course to start your journey.