solulubeta
Sign in
DSA Basics / Warm-up
01.01 · Problem

The Juice Stall Takings

Easy Single pass · running total Free

Ravi runs a juice stall outside the college gate. At the end of the day he has a note of what every customer paid, in the order they came. He wants to know how much money the stall took in altogether.

Given the list of payments, return the total.

Examples

Example 1

Input:  paid = [40, 25, 15]
Output: 80

The stall served three customers who paid 40, 25 and 15. Adding them up as you go gives 40, then 65, then 80, so the answer is 80.

Example 2

Input:  paid = [0, 0, 0]
Output: 0

Example 3

Input:  paid = [250]
Output: 250

Constraints

paid has at least 1 and at most 10,000 entries, and every amount is between 0 and 5,000 rupees.

Return a single number: the sum of all the payments.

How to solve it

Hint

You never need to look at two payments at once. Carry one number with you as you walk the list.

Approach: Single pass · running total
  1. Start a variable total at 0.
  2. Walk through the list once and add each payment to total.
  3. Return total after the loop.

Check with the example. 40 + 25 + 15 = 80, so the stall took 80 rupees.

Complexity: O(n) time, O(1) space.

The reference solutions in all four languages are in the Solutions tab of the workspace below.

Loading the workspace…
Mark this problem as solved when you are finished.

Item 1 of 90 · updated 2026-10-12