Grokking Data Structures & Algorithms for Coding Interviews
Ask Author
Back to course home

0% completed

Solution: Longest Nice Substring

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

  1. Example 1:

    • Input: "BbCcXxY"
    • Expected Output: "BbCcXx"
    • Justification: Here, "BbCcXx" is the longest substring where each letter's uppercase and lowercase forms are present.
  2. Example 2:

    • Input: "aZAbcD"
    • Expected Output: ""

.....

.....

.....

Like the course? Get enrolled and start learning!