Longest Uncommon Subsequence I
Too many down votes. But there are three cases that can give us the insight to come up with a concise solution. Read the editorial.


The code compares the two strings. If they are identical, there is no uncommon subsequence, so it returns 1. If they are different, the entire string of either a
or b
will be an uncommon subsequence, so it returns the length of the longer string.
Identifying Problem Isomorphism
“Longest Uncommon Subsequence I” has an approximate isomorphic “Nonoverlapping Intervals”.
In “Longest Uncommon Subsequence I”, the task is to find the length of the longest uncommon subsequence between two strings. An uncommon subsequence between two strings is a string that is a subsequence of one but not the other.
“Nonoverlapping Intervals” is a problem where you’re given a collection of intervals, and you have to eliminate the minimum number of intervals such that no two intervals are overlapping.
They seem different on the surface but share an underlying concept. The logic behind finding an uncommon subsequence is similar to finding nonoverlapping intervals. In both cases, we are seeking elements (sequences or intervals) that don’t exist in another context (another string or overlapping with another interval).
“Nonoverlapping Intervals” is a more complex problem, as it involves an additional step of figuring out the minimum number of intervals to be removed.
The mapping is approximate because the direct elements and conditions of the problems differ, but they share an underlying concept of dealing with unique or nonoverlapping entities.


Problem Classification
This problem falls under string manipulation and sequence comparison.
What Components:
Two Input Strings: The problem gives us two strings,
a
andb
, which we are going to compare.Uncommon Subsequence: We are asked to identify a string that is a subsequence of one string but not the other, meaning it is unique to one of the strings.
Length of Longest Uncommon Subsequence: The problem asks us to find not just any uncommon subsequence, but the longest one. We have to return the length of this longest uncommon subsequence.
Nonexistence of Uncommon Subsequence: In case an uncommon subsequence doesn’t exist, we are required to return 1.
This is a comparison problem involving sequences (strings in this case). It requires the understanding of the concept of subsequences in strings, which is a common topic in dynamic programming and string manipulation problems.
Understand how strings are manipulated, compared, and how to derive subsequences from a given string. Also, decisionmaking skills are required to determine whether an uncommon subsequence exists and to identify the longest one among them. This problem might be considered to fall under comparative string analysis or dynamic programming, depending upon the approach used to solve it.
The categorization of the problem would be a Comparative String Analysis problem.
Language Agnostic Coding Drills
 Dissect the Code
The provided code is a Python solution for the problem statement. Here are the individual concepts used:
Defining a function: The syntax to define a function in Python using
def
keyword.Condition Checking: Using
if
to check for a condition (whether the two strings are equal).Returning Values: Using the
return
keyword to send a result back from a function.Using
else
clause: The code includes anelse
statement, which executes when theif
condition is False.Builtin Functions: The use of Python’s builtin
len()
function to get the length of a string, and themax()
function to get the maximum of the provided values.
List of Concepts by Increasing Difficulty
Defining a function: The simplest concept here, an essential building block in any Python script. Difficulty: Easy.
Returning Values: Another basic concept, returning a value from a function is crucial to any piece of Python code. Difficulty: Easy.
Builtin Functions:
len()
andmax()
are simple builtin Python functions. They take a little understanding of what they do, but usage is straightforward. Difficulty: Easy.Condition Checking: Using
if
is not difficult, but it requires a solid understanding of Boolean expressions and control flow. Difficulty: Intermediate.Using
else
clause: This requires a good understanding of control flow and is contingent on understandingif
conditions. Difficulty: Intermediate.
Problemsolving Approach
The solution first checks if the two strings
a
andb
are the same. If they are, there cannot be an “uncommon” subsequence because all subsequences ofa
are also subsequences ofb
and vice versa. Therefore, it returns1
.If the two strings are not the same, the longest uncommon subsequence would be one of the strings itself because one string cannot be a subsequence of the other (they are different). Therefore, it finds the length of both strings and returns the length of the longer string.
Each concept in the code contributes to the final solution. The concepts of function definition, condition checking, and returning values form the basic structure of the code, while the use of builtin functions accomplishes the specific tasks needed to solve the problem (i.e., comparing the lengths of the strings and finding the maximum). These concepts are combined in the given order to come up with a comprehensive solution to the problem.
Targeted Drills in Python
 Python Coding Drills
 Defining a function: Here’s a simple example of a Python function definition. It’s a function that adds two numbers and returns the result.


 Returning Values: Here’s a simple Python function that returns a value. It’s a function that returns the phrase “Hello, World!”.


 Builtin Functions: Here’s an example of how to use the builtin Python function
len()
andmax()
.


 Condition Checking: Here’s a Python code snippet that checks if a number is positive.


 Problemspecific Concepts
The current problem is quite straightforward and doesn’t involve any complex problemspecific concepts that would require separate drills. The main principle is understanding that if the strings are identical, there’s no uncommon subsequence, and if they are not identical, the entire length of the longest string can be an uncommon subsequence.
 Integrating the Drills
The general process to integrate these drills would be:
 Define a function that takes two strings as parameters (Function definition drill).
 Check if the two strings are equal using an if statement (Condition Checking drill).
 If they are equal, return
1
(Returning Values drill).  If they are not equal, calculate the length of both strings, find the maximum length, and return that (Builtin Functions drill).
These concepts, when integrated, create the final solution.