PracHub
QuestionsCoachesLearningGuidesInterview Prep

Quick Overview

This question evaluates string processing and algorithmic optimization skills, specifically handling simulated deletions (backspace behavior) and performing comparisons under a strict auxiliary space constraint.

  • medium
  • N/A
  • Coding & Algorithms
  • Backend Engineer

Compare Strings With Deletions

Company: N/A

Role: Backend Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Technical Screen

You are given two strings `s` and `t`. Each string may contain lowercase letters and the special character `#`. A `#` deletes the closest non-deleted character immediately before it, if such a character exists; otherwise it has no effect. Return whether the two strings are equal after all deletions are applied. You must implement the comparison without using extra space proportional to the input size. Aim for `O(1)` auxiliary space. Example: ```text Input: s = "ab#c", t = "ad#c" Output: true Explanation: Both strings become "ac". ``` ```text Input: s = "a#c", t = "b" Output: false Explanation: The first string becomes "c", while the second becomes "b". ```

Quick Answer: This question evaluates string processing and algorithmic optimization skills, specifically handling simulated deletions (backspace behavior) and performing comparisons under a strict auxiliary space constraint.

Return whether two strings are equal after # deletes the previous non-deleted character, using O(1) auxiliary space.

Constraints

  • Strings contain lowercase letters and #

Examples

Input: ('ab#c', 'ad#c')

Expected Output: True

Explanation: Both become ac.

Input: ('a#c', 'b')

Expected Output: False

Explanation: Different results.

Input: ('###', '')

Expected Output: True

Explanation: Deletes past start.

Input: ('xywrrmp', 'xywrrmu#p')

Expected Output: True

Explanation: Equal after deletion.

Hints

  1. Scan backwards while counting pending deletions.
Last updated: Jun 27, 2026

Related Coding Questions

  • Implement Linear Regression Training - N/A

Loading coding console...

PracHub

Master your tech interviews with 8,000+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities
  • Student Access

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • AI Coding Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.