LeetCode 522, Medium. Topics: Array, Hash Table, Two Pointers, String, Sorting. View on LeetCode.
Generate this problem as a practice environment: tested reference solution, 18 parametrized pytest cases, and a playground notebook:
Problem
Given an array of strings <code>strs</code>, return <em>the length of the <strong>longest uncommon subsequence</strong> between them</em>. If the longest uncommon subsequence does not exist, return <code>-1</code>.
An <strong>uncommon subsequence</strong> between an array of strings is a string that is a <strong>subsequence of one string but not the others</strong>.
A <strong>subsequence</strong> of a string <code>s</code> is a string that can be obtained after deleting any number of characters from <code>s</code>.
<ul>
<li>For example, <code>“abc”</code> is a subsequence of <code>“aebdc”</code> because you can delete the underlined characters in <code>“a<u>e</u>b<u>d</u>c”</code> to get <code>“abc”</code>. Other subsequences of <code>“aebdc”</code> include <code>“aebdc”</code>, <code>“aeb”</code>, and <code>""</code> (empty string).</li>
</ul>
Examples
Constraints
- 2 <= strs.length <= 50
- 1 <= strs[i].length <= 10
- strs[i] consists of lowercase English letters.
Solution
Reference implementation from solution.py on GitHub, full suite in test_solution.py:
Complexity
Last modified on September 7, 2026