> ## 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.

# Longest Uncommon Subsequence I Python Solution

> Tested Python solution for LeetCode 521 with 22 pytest cases. Generate a practice environment with lcpy.

LeetCode 521, [Easy](/catalog/easy). Topics: [String](/catalog/topics/string). [View on LeetCode](https://leetcode.com/problems/longest-uncommon-subsequence-i/description/).

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

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

## Problem

Given two strings `a` and `b`, return the length of the **longest uncommon subsequence** between `a` and `b`. If no such uncommon subsequence exists, return `-1`.

An **uncommon subsequence** between two strings is a string that is a subsequence of exactly one of them.

### Examples

```
Input: a = "aba", b = "cdc"
Output: 3
Explanation: One longest uncommon subsequence is "aba" because "aba" is a subsequence of "aba" but not "cdc".
Note that "cdc" is also a longest uncommon subsequence.
```

```
Input: a = "aaa", b = "bbb"
Output: 3
Explanation: The longest uncommon subsequences are "aaa" and "bbb".
```

```
Input: a = "aaa", b = "aaa"
Output: -1
Explanation: Every subsequence of string `a` is also a subsequence of string `b`.
```

### Constraints

* 1 \<= a.length, b.length \<= 100
* `a` and `b` consist of lower-case English letters.

## Solution

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

```python theme={"theme":{"light":"github-light","dark":"github-dark"}}
class Solution:
    # Time: O(min(len(a), len(b)))
    # Space: O(1)
    def find_luslength(self, a: str, b: str) -> int:
        # A whole string is always a subsequence of itself, so if a != b the
        # longer (or either, on a tie) string cannot be a subsequence of the
        # other: equal-length subsequences imply equality. If a == b every
        # subsequence is shared, so nothing is uncommon.
        return max(len(a), len(b)) if a != b else -1
```

## Complexity

| Time | Space |
| - | - |
| O(min(len(a), len(b))) | O(1) |

## Tags


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