# The Price Bander

> Different prices, different treatment.

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

Domain: Python · Difficulty: easy · Seniority: L4

## Problem

Given a dict mapping product names to prices, return a new dict mapping each product name to 'low' (price < 10), 'mid' (price < 50), or 'high' (otherwise).

## Worked solution and explanation

### Why this problem exists in real interviews

This tests **conditional categorization within a dictionary transformation**. It checks whether candidates can apply if/elif/else logic while iterating over dict entries, a common pattern in data labeling and bucketing.

---

### Break down the requirements

#### Step 1: Iterate over each product and price

Walk through the dictionary's key-value pairs.

#### Step 2: Classify each price into a tier

Apply the threshold rules: `< 10` is 'low', `< 50` is 'mid', otherwise 'high'.

#### Step 3: Build the result dict

Map each product name to its computed tier.

---

### The solution

**Threshold-based tier classification**

```python
def price_bands(products):
    result = {}
    for name in products:
        price = products[name]
        if price < 10:
            result[name] = 'low'
        elif price < 50:
            result[name] = 'mid'
        else:
            result[name] = 'high'
    return result
```

> **Time and Space Complexity**
>
> **Time:** O(n) where n is the number of products.
> 
> **Space:** O(n) for the output dictionary.

> **Interviewers Watch For**
>
> Is your threshold ordering correct? Checking `< 10` before `< 50` matters because a price of 5 satisfies both conditions. The order ensures 'low' is assigned first.

> **Common Pitfall**
>
> Using `<=` instead of `<` at the boundaries. A price of exactly 10 should be 'mid', not 'low'. Read the thresholds carefully.

---

## Common follow-up questions

- What if the tier thresholds were configurable? _(Tests accepting a list of (threshold, label) pairs and iterating them.)_
- How would you count products per tier? _(Tests adding a counter dict alongside the classification.)_
- What if prices could be negative? _(Tests whether negative prices fall into 'low' correctly.)_

## Related

- [All practice problems](https://datadriven.io/problems)
- [Mock interview mode](https://datadriven.io/interview/the_price_bander)
- [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.