10 XP challenge

Find the First Purchase Over Budget

easy
Build it yourself · 6 min
1 Learn2 Predict3 Solve

Task
Your mission

Purchases happen in the order listed in prices. Return the first index where the cumulative cost exceeds budget, or -1 if it never does. prices has 0 to 30 integer costs from 0 to 100; budget is 0 to 1000.

Examples

InputReturn
prices = [3,4,5], budget = 7

spent: 0 → 3 → 7 → 12. The result is 2.

2
prices = [3,4], budget = 7

spent: 0 → 3 → 7. The result is -1.

-1

Your code

Write your answer inside Solution, then use return to send it back.

Try examples runs the public examples. Check my code checks your full answer and saves your completion.