Make The String Great

EasyStackstack

Solve this the way you would in the interview: out loud, on a timer, with an AI interviewer asking follow-ups while you code. You get a scored report at the end.

Practice this as a mock interviewFree to start, no account needed

Problem

You are given a string s of uppercase and lowercase English letters. Two adjacent characters form a **bad pair** when they are the same letter in opposite cases, such as "aA" or "Aa". Two equal characters in the same case (like "aa") are not a bad pair. Repeatedly delete any bad pair until none remain, and return the resulting string. The result does not depend on the order of deletions. It may be empty. Aim for O(n) time.

Examples

Input: s = "xabBAy"
Output: "xy"
Removing "bB" gives "xaAy"; then "aA" is a bad pair, leaving "xy".
Input: s = "aa"
Output: "aa"
Both letters are lowercase, so they are not a bad pair.
Input: s = "Pp"
Output: ""
The whole string is one bad pair, so the result is empty.

Constraints

  • 1 <= s.length <= 100
  • `s` contains only uppercase and lowercase English letters.

What the interviewer grades

A correct solution is one of five scores. The report also grades problem understanding (did you clarify inputs and edge cases before coding), problem solving, communication while you work, code quality, and testing. See a sample report, or read up on the pattern in the lessons.

More stack problems