PracHub
QuestionsPremiumCoachesLearningGuidesInterview Prep

Quick Overview

This question evaluates string manipulation and combinatorial reasoning about character swaps and anagram formation, focusing on competencies such as frequency analysis and reasoning about minimal edit operations.

  • Medium
  • DoorDash
  • Coding & Algorithms
  • Software Engineer

Determine equality after limited swaps

Company: DoorDash

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: Medium

Interview Round: Technical Screen

##### Question LeetCode 1790. Check if One String Swap Can Make Strings Equal Follow-up: Given two strings, determine if they can become anagrams of each other using at most k swaps https://leetcode.com/problems/check-if-one-string-swap-can-make-strings-equal/description/

Quick Answer: This question evaluates string manipulation and combinatorial reasoning about character swaps and anagram formation, focusing on competencies such as frequency analysis and reasoning about minimal edit operations.

Given two strings s and t of equal length and a non-negative integer k, you may perform swaps of adjacent characters in s (i.e., swap s[i] and s[i+1]). Determine whether s can be transformed into t using at most k such swaps. If s and t do not have the same multiset of characters, return false.

Constraints

  • 1 <= len(s) = len(t) <= 200000
  • s and t consist only of lowercase English letters ('a'-'z')
  • 0 <= k <= 10^12

Hints

  1. If s and t do not have identical character frequencies, it is impossible.
  2. Match the k-th occurrence of each character in s to the k-th occurrence of the same character in t to form a permutation of target indices.
  3. The minimum number of adjacent swaps equals the inversion count of that permutation.
  4. Use a Binary Indexed Tree (Fenwick Tree) or a mergesort-based approach to count inversions in O(n log n).
Last updated: Mar 29, 2026

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
  • Compare Platforms
  • Discord Community

Support

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

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.

Related Coding Questions

  • Validate a Shopping Cart - DoorDash (medium)
  • Calculate Driver Payments - DoorDash (medium)
  • Implement Timeout Refund Workflow - DoorDash (medium)
  • Maximize Chef Assignment Profit - DoorDash (medium)
  • Compute Courier Delivery Pay - DoorDash (easy)