JPMorgan ChaseOA #17
Eliminate Substring
Estimated MediumJudge-ready
Topics (AI-labelled)Stacks & HeapsStrings
Repeatedly delete AWS from an uppercase string, joining the two sides of each deletion, until AWS no longer appears; output −1 if the result is empty.
Input
One line with a string of uppercase English letters, of length 1..100000.
Output
Output the final string; output −1 if it is empty.
Example 1
Input:
AWAWSSG
Output:
G
Example 2
Input:
AWS
Output:
-1
Example 3
Input:
AWSSAWS
Output:
S
Example notes
The outputs of the three public examples are, in order: G; -1; S. These answers have been checked by independent enumeration or direct simulation.
Editorial
Loading solution…