MEDIUMasked at 1 company

Determine if Two Strings Are Close

A medium-tier problem at 54% community acceptance, tagged with Hash Table, String, Sorting. Reported in interviews at Postmates and 0 others.

Founder's read

You have two strings and need to determine if they're 'close' according to specific rules: you can swap any two characters within each string, and you can transform any character into any other character. Most candidates misread this as a standard anagram problem and lose 20 minutes chasing a dead end. It's not about counting character frequencies. It's about what transformations the rules actually allow. Postmates has asked this. If you blank on the actual constraint during the assessment, StealthCoder runs invisibly and surfaces the working approach in seconds.

Companies asking
1
Difficulty
MEDIUM
Acceptance
54%

Companies that ask "Determine if Two Strings Are Close"

If this hits your live OA

Determine if Two Strings Are Close is the kind of problem that decides whether you pass. StealthCoder reads the problem on screen and surfaces a working solution in under 2 seconds. Invisible to screen share. The proctor sees nothing. Built by a senior engineer who knows the OA is theater. This is the script.

Get StealthCoder
What this means

The trick is recognizing that the rules split into two independent checks. First, both strings must have the exact same set of distinct characters, because you can only transform characters that exist in your original string. Second, the frequency arrays must be identical when sorted, because swapping lets you rearrange characters freely within each string, but doesn't change the multiset of frequencies you have. Most candidates try to match frequencies directly or overcomplicate the transformation rule. The obvious brute-force approach fails because it misses that sorting the frequency counts is the key insight. When this problem hits your live OA and the wording throws you, StealthCoder solves it without the guesswork.

Pattern tags

The honest play

You know the problem. Make sure you actually pass it.

Determine if Two Strings Are Close recycles across companies for a reason. It's medium-tier, and most candidates blank under the timer. StealthCoder is the hedge: an AI overlay invisible during screen share. It reads the problem and surfaces a working solution in under 2 seconds. Built by a senior engineer who knows the OA is theater. This is the script. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Determine if Two Strings Are Close interview FAQ

Is this actually an anagram problem?+

No. Anagrams require the same characters in the same frequencies. This problem lets you transform any character into any other, so matching character sets and sorted frequency arrays is the real constraint. The transformation rule is more permissive than anagram logic.

Why do I need to sort the frequency arrays?+

Swapping characters within a string doesn't change the count of how many times each frequency appears. If string A has frequencies [1, 2, 3] and string B has [1, 2, 3], you can rearrange A to match B's frequency distribution through swaps alone. Sorted frequencies capture this equivalence.

What's the runtime complexity I should target?+

O(n log n) due to sorting the frequency arrays. Counting characters is O(n). Comparing sorted frequency lists is O(26) since there are at most 26 distinct letters. Most solutions use Hash Table and Sorting together, which is optimal for this problem.

Is this asked frequently at FAANG?+

This is lower frequency overall. Postmates has been reported asking it. It's medium difficulty with a 54 percent acceptance rate, so candidates who understand the two-check structure solve it cleanly, but misreading the rules trips many up.

What's the most common mistake?+

Trying to match character frequencies directly instead of recognizing that sorting the frequency counts is the real check. Candidates also overread the transformation rule and think it's more powerful than it is. Slow down on the problem statement and sketch out the two separate conditions.

Want the actual problem statement? View "Determine if Two Strings Are Close" on LeetCode →

Frequency and company-tag data sourced from public community-maintained interview-report repos. Problem, description, and trademark © LeetCode. StealthCoder is not affiliated with LeetCode.