Basic threshold stop
Input
take_until([1, 2, 3, 4], 5)
Output
[1, 2, 3]
Cumulative sums: 1, 3, 6. 6 >= 5 at the third element, so return [1, 2, 3].
Full lesson preview
Iterate through a sequence and collect items until a cumulative condition is satisfied.
Problem statement
Task
Examples
Input
take_until([1, 2, 3, 4], 5)
Output
[1, 2, 3]
Cumulative sums: 1, 3, 6. 6 >= 5 at the third element, so return [1, 2, 3].
Input format
Output format
Constraints
Samples
Input
take_until([10, -1, 5], 8)
Output
[10]
10 >= 8 immediately, so only the first element is returned.