dsa · easy

Longest Uncommon Subsequence

A subsequence of a string is the original string after deleting zero or more characters, keeping the rest in order. An **uncommon** subsequence of a and b is a string that is a subsequence of exactly one of them.

Arguments

Return the length of the longest uncommon subsequence, or -1 if none exists.

Example

a = "aba", b = "cdc"

The two strings differ. Either whole string is a subsequence of itself and not of the other, so the longest length is max(3, 3) = 3.

a = "aaa", b = "aaa" — every subsequence of one is a subsequence of the other → -1.

Constraints

1 <= a.length, b.length <= 100 a and b consist of lowercase English letters Hidden tests include near-max size for this bound; a slower-than-intended solution TLEs.

Examples

Example 1

Input:
"aba"
"cdc"

Expected:
3

Example 2

Input:
"aaa"
"aaa"

Expected:
-1

Example 3

Input:
"a"
"aa"

Expected:
2

Open in the Dojo editor