Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Palindrome and Backspace String Compare

EasyPython00:00
Practice interviewer
In session
5 left
00:00

Your question is Palindrome and Backspace String Compare. Start with the requirements on the right.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.

Problem

Akamai Control Center may represent user-edited filter text before it is submitted. In these strings, # acts as a backspace that removes the most recent valid character to its left. Compare two strings and determine whether they produce the same final text.

Formal Specification

Implement backspace_compare(s, t), where s and t are strings containing lowercase English letters and #. Return True if both strings are equal after applying all backspaces, otherwise return False.

A backspace with no available character has no effect. The solution should avoid constructing the fully edited strings when possible.

Constraints

  • 0 <= len(s), len(t) <= 2 * 10^5
  • s and t contain only lowercase English letters and #
  • Backspaces without a preceding valid character are ignored
  • The algorithm should use O(len(s) + len(t)) time

Function Signature

def backspace_compare(s, t):
Your solutionPython 3
You need to log in / sign up to run or submit.
Run your code to see test output