Practice Longest Nice Substring
Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.
Longest Nice Substring
Problem Statement
A string s is nice if, for every letter of the alphabet that s contains, it appears both in uppercase and lowercase. For example, "abABB" is nice because 'A' and 'a' appear, and 'B' and 'b' appear. However, "abA" is not because 'b' appears, but 'B' does not. Given a string s, return the longest substring of s that is nice. If there are multiple, return the substring of the earliest occurrence. If there are none, return an empty string.
Source: Longest Nice Substring on LeetCode. Use the original task for its coding environment and submissions.
Examples
# Example 1
s = "YazaAay"
"aAa"
# Example 2
s = "Bb"
"Bb"
# Example 3
s = "c"
""
Constraints
Related LeetCode Problems
Practice more problems similar to Longest Nice Substring.
Review your practice with PhantomCodeAI
After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.