Make The String Great

A string is good when no two neighbouring characters are the same letter in opposite cases, such as `"aA"` or `"Bb"`. Given a string `s` of English letters, repeatedly delete such a neighbouring pair until the string is good, and return it. The answer is unique, and an empty string counts as good.

30:00

Make The String Great
easy
Free written solution
Topics
Companies

A string is good when no two neighbouring characters are the same letter in opposite cases, such as "aA" or "Bb". Given a string s of English letters, repeatedly delete such a neighbouring pair until the string is good, and return it. The answer is unique, and an empty string counts as good.

Example 1:
Input: {"s":"leEeetcode"}
Output: leetcode
Constraints:
  • 1≤s.length≤1001 \leq s.\text{length} \leq 100

  • s contains only lowercase and uppercase English letters.

Test Cases
Input (Stdin)
Expected Output (Stdout)
Execution Result

Run code to see results.

Input
arr ={"s":"leEeetcode"}

s: cancelled twins share a colour

lowercase · UPPERCASE

l

0

e

1

E

2

e

3

e

4

t

5

c

6

o

7

d

8

e

9

Read the letters left to right. The stack holds the good prefix so far; a new letter can only clash with the top.

stack (good prefix) ← arriving letter

size 0

empty

pairs cancelled 0
letters read 0 / 10
Variables
VariableValue
stack
DepthFunction Call
Stack empty
0/21