Skip to the editor
JSGroundwork
JSGroundwork handwritten · web dev
←Back to Two pointers

Ready to read

JSJavaScript⑂Git◎Interview prepΣDSA in JSSDSystem Design
More topics15›
</>HTML{ }CSS⚛ReactNNext.jsNeNest.jsTSTypeScriptNoNode.js🐳DockerDBSQL & Databases✓Testing🔒Web Security☁Cloud & DevOps◈GraphQL◆Redis☸Kubernetes
☰‹›
Description
All topics›JavaScript›Two pointers

Backspace String Compare

intermediatelayer B4 · Two pointers5 tests

Two strings s and t are typed into an editor where '#' means backspace. Return true if they produce the same final text.

  • A backspace on empty text does nothing — it does not error, and it does not carry over. For example "a##c" and "#a#c" both end up as "c"
  • Two empty results are equal, so "###" and "" match
  • Building both strings with a stack is O(n) time but O(n) space. Aim for O(1) extra space by walking both strings from the BACK
  • Return an actual boolean

Stuck?

All exercisesPlayground
1234567891011121314
loading the editor…

Nothing yet — hit Run and whatever you log shows up here.

Submit to see how you did.

⌘/Ctrl + Enter run⌘/Ctrl + S save⌘/Ctrl + / comment⌘/Ctrl + F find/replace⌘/Ctrl + D select next matchAlt + click multi-cursorTab indent · ⇧Tab outdentEsc leave fullscreen