Skip to content

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.

Easy#1763
LeetCode Problem

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

Input
s = "YazaAay"
Output
"aAa"

# Example 2

Input
s = "Bb"
Output
"Bb"

# Example 3

Input
s = "c"
Output
""

Constraints

1 <= s.length <= 100
s consists of uppercase and lowercase English letters.

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.