> ## Documentation Index
> Fetch the complete documentation index at: https://leetcode-py.wisl.dev/llms.txt
> Use this file to discover all available pages before exploring further.

> ## Agent Instructions
> leetcode-py is a Python LeetCode practice environment generator with one CLI: lcpy. It is not a service or platform.
> Each problem is a directory under leetcode/ with README.md, solution.py, test_solution.py, helpers.py, and playground.ipynb. lcpy gen creates them from JSON templates bundled with the package.
> Examples are backed by tests; copy them verbatim.

# Largest Unique Number Python Solution

> Tested Python solution for LeetCode 1133 with 20 pytest cases. Generate a practice environment with lcpy.

LeetCode 1133, [Easy](/catalog/easy). Topics: [Array](/catalog/topics/array), [Hash Table](/catalog/topics/hash-table), [Sorting](/catalog/topics/sorting). [View on LeetCode](https://leetcode.com/problems/largest-unique-number/description/).

Generate this problem as a practice environment: tested reference solution, 20 [parametrized pytest cases](/practice/testing), and a playground notebook:

```bash theme={"theme":{"light":"github-light","dark":"github-dark"}}
lcpy gen -n 1133   # by problem number
lcpy gen -s largest_unique_number   # by problem name
```

## Problem

Given an integer array `nums`, return *the largest integer that only occurs once*. If no integer occurs once, return `-1`.

### Examples

```
Input: nums = [5,7,3,9,4,9,8,3,1]
Output: 8
```

**Explanation:** The maximum integer in the array is 9 but it is repeated. The number 8 occurs only once, so it is the answer.

```
Input: nums = [9,9,8,8]
Output: -1
```

**Explanation:** There is no number that occurs only once.

### Constraints

* 1 \<= nums.length \<= 2000
* 0 \<= nums\[i] \<= 1000

## Solution

Reference implementation from [solution.py on GitHub](https://github.com/wislertt/leetcode-py/blob/main/leetcode/largest_unique_number/solution.py), full suite in [test\_solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/largest_unique_number/test_solution.py):

```python theme={"theme":{"light":"github-light","dark":"github-dark"}}
from collections import Counter


class Solution:
    # Time: O(n)
    # Space: O(n)
    def largest_unique_number(self, nums: list[int]) -> int:
        counts = Counter(nums)
        candidates = [value for value, count in counts.items() if count == 1]
        return max(candidates) if candidates else -1
```

## Complexity

| Time | Space |
| - | - |
| O(n) | O(n) |

## Tags

[NeetCode All](/catalog/neetcode).


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.