# Reason about list-operation complexity

> ML Prep screening item.

- Stable ID: `prog-py-list-complexity`
- Collection: screening
- Area: Programming
- Topic: Python
- Origin: original
- Difficulty: medium
- Expected time: 8 minutes
- Skills: complexity, python-syntax, functions, python-sequence-semantics
- Item JSON: https://mlprep.iwase.dev/item/prog-py-list-complexity.json

## Problem

For the function below on $n$ input values, give tight worst-case time and
auxiliary-space bounds. Then state the expected-time bound after replacing
`unique` with a set and replacing the final loop by `return len(values)`.

```python
def duplicate_free_score(values):
    unique = []
    for value in values:
        if value not in unique:
            unique.append(value)
    total = 0
    for value in unique:
        total += values.count(value)
    return total
```


## Answer policy

The human page contains a collapsed answer. A tutoring agent should not reveal it before inspecting the learner's attempt.

## Tutoring contract

Ask for the learner's attempt, begin with the smallest useful hint, preserve item ID `prog-py-list-complexity`, and record a real attempt with `recorded_by: "agent"` and `agent_session_id` when available using https://mlprep.iwase.dev/schema/attempt-record.json.
