# The Bronze Medalist

> Not first, not last - somewhere in the middle of the podium.

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

Domain: Python · Difficulty: easy · Seniority: L3

## Problem

Given a list of integers and integer k, return the k-th largest distinct-position value (by rank; k=1 is the max). You may use built-in sorting.

## Worked solution and explanation

### Why this problem exists in real interviews

Finding the k-th largest element tests **sorting and indexing**. While the prompt allows built-in sorting, interviewers use this to transition into discussions about quickselect and heap-based approaches.

---

### Break down the requirements

#### Step 1: Sort the list in descending order

This places the largest element at index 0, second largest at index 1, etc.

#### Step 2: Return the element at index k-1

The k-th largest is at position k-1 in a 0-indexed descending-sorted list.

---

### The solution

**Sort descending and index for k-th largest**

```python
def kth_largest(nums, k):
    sorted_nums = sorted(nums, reverse=True)
    result = sorted_nums[k - 1]
    return result
```

> **Time and Space Complexity**
>
> **Time:** O(n log n) for the sort.
> 
> **Space:** O(n) for the sorted copy.

> **Interviewers Watch For**
>
> Whether you mention quickselect for O(n) average time, or `heapq.nlargest(k, nums)` for O(n log k). The sort approach is accepted but not optimal.

> **Common Pitfall**
>
> Off-by-one: using index `k` instead of `k-1`. The 1st largest is at index 0.

---

## Common follow-up questions

- Can you solve this in O(n) average time? _(Tests quickselect: partition around a pivot and recurse into the relevant half.)_
- What if k is very small relative to n? _(Tests using a min-heap of size k for O(n log k) time.)_
- What if the list contains duplicates? _(Tests clarifying whether 'k-th largest' means distinct values or by position.)_

## Related

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