10 XP challenge
Find the First Purchase Over Budget
easy
Build it yourself · 6 min
1 Learn2 Predict3 Solve
TaskYour 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
| Input | Return |
|---|---|
prices = [3,4,5], budget = 7spent: 0 → 3 → 7 → 12. The result is 2. | 2 |
prices = [3,4], budget = 7spent: 0 → 3 → 7. The result is -1. | -1 |
Your code
Write your answer inside Solution, then use return to send it back.
Ln 1, Col 1
JavaScript
Try examples runs the public examples. Check my code checks your full answer and saves your completion.