Determine if Two Strings Are Close

Medium

Description

Two strings are close if you can attain one from the other using operations: swap characters or transform characters by frequency.

Examples

Input:word1 = "abc", word2 = "bca"
Output:true
Explanation:

Can swap to match.

Input:word1 = "a", word2 = "aa"
Output:false
Explanation:

For word1 = "a", word2 = "aa", the answer is false because the determine if two strings are close condition is not met.

Input:word1 = "cabbba", word2 = "abbccc"
Output:true
Explanation:

For word1 = "cabbba", word2 = "abbccc", the answer is true because the determine if two strings are close condition is satisfied.

Constraints

  • 1 ≤ word1.length, word2.length ≤ 10⁵

Ready to solve this problem?

Practice solo or challenge other developers in a real-time coding battle!