Longest Nice Substring Problem
Longest Nice Substring Problem — ExecCode Easy DSA Practice
Solve the Longest Nice Substring problem on ExecCode. Free online easy DSA practice in Hashing. Write and run code in Java, C++, Python — no signup required to run.
Problem description
Description You are given a string s, return the longest substring of s that is nice. Your task is to if there are multiple, return the substring of the earliest occurrence. 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. If there are none, return an empty string.
Examples
Input {"s": "YazaAay"}; Output aAa. Input {"s": "Bb"}; Output Bb
Constraints
1 <= s.length <= 100 s consists of uppercase and lowercase English letters.
Practice Longest Nice Substring free on ExecCode. Browse DSA problems, topic map, and placement guides.