Problem · String
Backspace String Compare
Learn this problemProblem statement
Two strings are said to be the same if they are of the same length and have the same character at each index. Backspacing in a string removes the previous character in the string.
Given two strings containing lowercase English letters and the character # which represents a backspace key,
determine if the two final strings are equal. Return 1 if they are equal or 0 if they are not.
Note that backspacing an empty string results in an empty string.
Function
compareStrings(s1: String, s2: String) → int
Complete the function compareStrings in the editor below.
compareStrings has the following parameter(s):
string s1: the first stringstring s2: the second string
Returns
int: either 0 or 1
Examples
Example 1
s1 = "axx#b#b#c"s2 = "axbdf#c#c"return = 1In the first string, one 'x' and one 'b' are backspaced over. The first string becomes
axbc.
The second string also becomes axbc. The answer is 1.Constraints
1 <= length of s1 <= 2*1051 <= length of s2 <= 2*105Both s1 and s2 contain lowercase English letters and/or the char '#' only :)More Goldman Sachs problems
- Data ReorganizationSeen Jul 2026
- Inherited Role PermissionsONSITE INTERVIEW · Seen Jul 2026
- Root of the Largest TreePHONE SCREEN · Seen Jul 2026
- Validate Binary Search TreeONSITE INTERVIEW · Seen Jul 2026
- Alternating Parity PermutationsOA · Seen Jul 2026
- Threshold AlertsSeen Jul 2026
- Cheapest Flights Within K StopsONSITE INTERVIEW · Seen Jun 2026
- Word LadderPHONE SCREEN · Seen Jun 2026