cswork / OAOpen practice workspace

Goldman SachsOA #3

Backspace String Compare

EasyJudge-ready

Topics (AI-labelled)Stacks & HeapsStrings

Given two strings consisting only of lowercase English letters and #. # is a backspace that deletes the single character immediately before it in the current string; if the string is empty at that moment, it has no effect. Determine whether the two strings are equal after each is processed; output 1 if they are equal, otherwise output 0.

Input

Two lines with the non-empty strings s1 and s2. Complete original constraints: 1≤|s1|,|s2|≤200000; characters are only lowercase English letters or #. The ranges come from the complete raw of the fixed submission; the 1 5 in the compiled MDX is a corrupted fragment. The two-line standard input/output is this site's wrapper.

Output

Output 1 if they are equal, otherwise output 0.

Example 1

Input:

axx#b#b#c
axbdf#c#c

Output:

0

Example notes

A backspace on an empty string does nothing; all other rules follow the original definition. You can scan from right to left while counting characters to skip, or use a stack.

Editorial

Loading solution…