PracHub
QuestionsPremiumLearningGuidesCheatsheetNEWCoaches
|Home/Coding & Algorithms/DoorDash

Can two names match with ≤2 swaps?

Last updated: Mar 29, 2026

Quick Overview

This question evaluates string manipulation and combinatorial reasoning skills, focusing on character multisets, permutations, and the implications of a bounded number of swap operations.

  • medium
  • DoorDash
  • Coding & Algorithms
  • Software Engineer

Can two names match with ≤2 swaps?

Company: DoorDash

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Technical Screen

You are given two restaurant names represented as strings `s` and `t` of equal length (same character set, case-sensitive). In one operation, you may **swap** any two characters in `s` (i.e., pick indices `i` and `j` and exchange `s[i]` and `s[j]`). You may perform **at most 2 swaps**. Return `true` if you can transform `s` into exactly `t` using at most 2 swaps; otherwise return `false`. Constraints (reasonable assumptions): - `1 <= n = s.length = t.length <= 2e5` - Characters are ASCII letters (or lowercase English letters). Example: - `s = "abca"`, `t = "aabc"` -> `true` (swap indices 1 and 3 to get "aabc") - `s = "abcd"`, `t = "badc"` -> `true` (swap (0,1) then swap (2,3)) - `s = "abcd"`, `t = "abdc"` -> `true` (one swap) - `s = "abcd"`, `t = "abdd"` -> `false` (different multiset of characters)

Quick Answer: This question evaluates string manipulation and combinatorial reasoning skills, focusing on character multisets, permutations, and the implications of a bounded number of swap operations.

Related Interview Questions

  • Maximize Chef Assignment Profit - DoorDash (medium)
  • Compute Courier Delivery Pay - DoorDash (easy)
  • Compute Nearest Destination Distances - DoorDash (easy)
  • Count changed nodes between two menu trees - DoorDash (hard)
  • Calculate Daily Driver Pay - DoorDash (hard)
DoorDash logo
DoorDash
Jan 13, 2026, 12:00 AM
Software Engineer
Technical Screen
Coding & Algorithms
3
0

You are given two restaurant names represented as strings s and t of equal length (same character set, case-sensitive).

In one operation, you may swap any two characters in s (i.e., pick indices i and j and exchange s[i] and s[j]). You may perform at most 2 swaps.

Return true if you can transform s into exactly t using at most 2 swaps; otherwise return false.

Constraints (reasonable assumptions):

  • 1 <= n = s.length = t.length <= 2e5
  • Characters are ASCII letters (or lowercase English letters).

Example:

  • s = "abca" , t = "aabc" -> true (swap indices 1 and 3 to get "aabc")
  • s = "abcd" , t = "badc" -> true (swap (0,1) then swap (2,3))
  • s = "abcd" , t = "abdc" -> true (one swap)
  • s = "abcd" , t = "abdd" -> false (different multiset of characters)

Comments (0)

Sign in to leave a comment

Loading comments...

Browse More Questions

More Coding & Algorithms•More DoorDash•More Software Engineer•DoorDash Software Engineer•DoorDash Coding & Algorithms•Software Engineer Coding & Algorithms
PracHub

Master your tech interviews with 7,500+ 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
  • Compare Platforms
  • Discord Community

Support

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

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.