# The Minutes Tracker

> Some activities eat more time than others.

Canonical URL: <https://datadriven.io/problems/the_minutes_tracker>

Domain: Python · Difficulty: easy · Seniority: L3

## Problem

Given a user record dict with 'activities' (list of dicts with 'type' and 'minutes'), return the total minutes summed across all activities.

## Worked solution and explanation

### Why this problem exists in real interviews

This tests **nested dictionary traversal** and basic accumulation. It checks whether candidates can navigate a real-world data structure (user record with embedded lists of activity dicts) and extract a single aggregate value.

---

### Break down the requirements

#### Step 1: Access the activities list from the user record

The user dict has a key `'activities'` whose value is a list of activity dicts.

#### Step 2: Sum the minutes across all activities

Loop through each activity and add its `'minutes'` value to a running total.

---

### The solution

**Simple loop accumulation over nested dicts**

```python
def total_minutes(user):
    total = 0
    for activity in user['activities']:
        total += activity['minutes']
    return total
```

> **Time and Space Complexity**
>
> **Time:** O(n) where n is the number of activities.
> 
> **Space:** O(1). Only a running total variable.

> **Interviewers Watch For**
>
> Do you access the dict keys confidently without unnecessary checks? The problem guarantees the structure, so defensive `get()` calls add noise without value here.

> **Common Pitfall**
>
> Trying to use `sum()` with a generator expression. While it works, interviewers at this level want to see the explicit loop to confirm you understand accumulation mechanics.

---

## Common follow-up questions

- What if some activities were missing the 'minutes' key? _(Tests using `.get('minutes', 0)` for defensive access.)_
- How would you return a breakdown by activity type? _(Tests switching from scalar to dict accumulation.)_
- What if the user record came from a JSON API response? _(Tests json.loads parsing before dict traversal.)_

## Related

- [All practice problems](https://datadriven.io/problems)
- [Mock interview mode](https://datadriven.io/interview/the_minutes_tracker)
- [Python Interview Questions](https://datadriven.io/python-interview-questions)
- [Data Engineering Interview Prep Guide](https://datadriven.io/data-engineer-interview-prep)
- [Daily Challenge](https://datadriven.io/daily)

---

Source: DataDriven (https://datadriven.io). 100% free data engineering interview prep. Live code execution against Postgres 16, Python 3.11, and Spark sandboxes. No paywall, no premium tier, no signup gate.