# Leetcode 522 - Longest Uncommon Subsequence II

Note:

• Sorting

• If the subsequence exists, it must be one of the element.
• Why? Coz it must be derived from one of the elements. The element must also be the sequence.
• How to check if one string is another one’s sub?
• Assume a.len < b.len. Iterate through the longers one, if b[i] === a[j], then j++, check if j === a.len. BTW, if a.len > b.len return false coz a longer one won’t be a shorter one’s subs. (Subs can only be derived by deleting chars, not adding.)
• Use double for loops to find it.
• Hash table

• Get all subsequences together.
• Use a map to count.
• The longest subs that only appear once is the answer.

Question:

Given an array of strings strs, return the length of the longest uncommon subsequence between them. If the longest uncommon subsequence does not exist, return -1.

An uncommon subsequence between an array of strings is a string that is a subsequence of one string but not the others.

A subsequence of a string s is a string that can be obtained after deleting any number of characters from s.

• For example, “abc” is a subsequence of “aebdc” because you can delete the underlined characters in “aebdc” to get “abc”. Other subsequences of “aebdc” include “aebdc”, “aeb”, and “” (empty string).

Example:

Code:

Sort then compare O(x * n^2)

Get all subs of a string O(n * 2^x)