← AlgoMindset 75

Determine if Two Strings Are Close

Medium🎙 Interview me on this

🧠 Before you code — what pattern fits?

Two strings are "close" if you can transform one into the other using: (1) swap any two existing characters, or (2) transform every occurrence of one existing character into another existing character, and vice versa.

Given two strings word1 and word2, return true if they are close.

("abc","bca") → true

("a","aa") → false

("cabbba","abbccc") → true

🎬 Video explanation · codestorywithMIK

Your solution runs against 4 unit tests, including edge and large-value cases.

Loading...

Test console · 4 unit tests

Submit your code to run it against all 4 unit tests. Results appear here.

JavaScript, TypeScript & Python run sandboxed in your browser; other languages run on the execution server. Your code is saved locally as you type.