Remove Adjacent Opposite-Case Copies of the Same Letter

Quick Overview

Remove Adjacent Opposite-Case Copies of the Same Letter. Repeatedly remove an adjacent pair consisting of the same English letter in opposite cases.

Remove Adjacent Opposite-Case Copies of the Same Letter

Company: Google

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: easy

Interview Round: Other

### Problem Repeatedly remove an adjacent pair consisting of the same English letter in opposite cases. Stop when no such pair remains and return the resulting string. The source guarantees the final result is unique,and the empty result is allowed. ```cpp class Solution { public: string makeGood(string s); }; ``` ### Examples **Example 1:** ```text Input: s = "aAB" Output: "B" Explanation: Remove adjacent aA; the remaining B has no partner. ``` **Example 2:** ```text Input: s = "mNnM" Output: "" Explanation: Remove Nn to expose mM,then remove that pair. ``` ### Constraints - s has length 1 to 100. - Only uppercase and lowercase English letters occur. - The fully reduced answer is guaranteed unique. ### Contract considerations Different deletion sequences do not create output freedom because the source guarantees one final string. ```hint Read the boundary condition Include removals that expose another removable pair. Same-case copies do not qualify, and the final result may be empty. ``` ### Boundary reminders Different deletion sequences do not create output freedom because the source guarantees one final string.

Overview: Remove Adjacent Opposite-Case Copies of the Same Letter. Repeatedly remove an adjacent pair consisting of the same English letter in opposite cases.

Google logo
Google
Jun 6, 2026
easySoftware EngineerOtherCoding & Algorithms
0
0

Problem

Repeatedly remove an adjacent pair consisting of the same English letter in opposite cases. Stop when no such pair remains and return the resulting string. The source guarantees the final result is unique,and the empty result is allowed.

class Solution {
public:
    string makeGood(string s);
};

Examples

Example 1:

Input: s = "aAB"
Output: "B"
Explanation: Remove adjacent aA; the remaining B has no partner.

Example 2:

Input: s = "mNnM"
Output: ""
Explanation: Remove Nn to expose mM,then remove that pair.

Constraints

  • s has length 1 to 100.
  • Only uppercase and lowercase English letters occur.
  • The fully reduced answer is guaranteed unique.

Contract considerations

Different deletion sequences do not create output freedom because the source guarantees one final string.

Boundary reminders

Different deletion sequences do not create output freedom because the source guarantees one final string.