Grokking Data Structures & Algorithms for Coding Interviews

0% completed

Problem 9: Make The String Great (easy)

Problem Statement

Given a string of English lowercase and uppercase letters, make the string "good" by removing two adjacent characters that are the same but in different cases.

Continue to do this until there are no more adjacent characters of the same letter but in different cases. An empty string is also considered "good".

Examples

Example 1

  • Input: "AaBCcdEeff"
  • Output: "Bdff"
  • Explanation: In the first step, "AaBCcDEeff" becomes "BcCDdEeff" because 'A' and 'a' are the same letter, but one is uppercase and the other is lowercase. Then we remove "cC", and "Ee"

.....

.....

.....

Like the course? Get enrolled and start learning!