Longest Uncommon Subsequence II

Medium

Description

Given an array of strings, find the longest uncommon subsequence. A string that is a subsequence of only one string has maximum length.

Examples

Input:strs = ["aba","cdc","eae"]
Output:3
Explanation:

All are uncommon.

Input:strs = ["abc","def","abc"]
Output:3
Explanation:

"def" is uncommon since it doesn't appear as a subsequence in any other string. "abc" appears twice, so neither instance is uncommon. The longest uncommon subsequence is "def" with length 3.

Input:strs = ["a","aa","aaa"]
Output:3
Explanation:

"a" is a subsequence of "aa" and "aaa", so it's not uncommon. "aa" is a subsequence of "aaa", so it's not uncommon. However, "aaa" is not a subsequence of "a" or "aa", making it uncommon with length 3.

Constraints

  • 2 ≤ strs.length ≤ 50

Ready to solve this problem?

Practice solo or challenge other developers in a real-time coding battle!