Back to course home
0% completed
Longest Nice Substring (easy)
Problem Statement
Given a string str
, return the longest nice
substring of a given string.
A substring is considered nice if for every lowercase letter in the substring, its uppercase counterpart is also present, and vice versa.
If no such string exists, return an empty string.
Examples
-
Example 1:
- Input:
"BbCcXxY"
- Expected Output:
"BbCcXx"
- Justification: Here,
"BbCcXx"
is the longest substring where each letter's uppercase and lowercase forms are present.
- Input:
-
Example 2:
- Input:
"aZAbcD"
- Expected Output:
""
- Input:
.....
.....
.....
Like the course? Get enrolled and start learning!