Tap here to switch tabs
Problem
Submissions

Problem: Determine if Two Strings Are Close

med
30 min
Try to solve the Determine if Two Strings Are Close problem.

Statement

Two strings are considered close if one can be transformed into the other by applying any sequence of the following operations:

  • Operation 11: Swap any two existing characters. For instance, abcde becomes aebcd.

  • Operation 22: Swap the frequencies of any two existing characters by transforming every occurrence of one existing character into another existing character, and vice versa. For instance, aacabb becomes bbcbaa by transforming all a characters to b and all b characters to a.

You may apply these operations on either string as many times as needed.

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

Constraints:

  • 1≤1 \leq word1.length, word2.length ≤105\leq 10^5

  • word1 and word2 contain only lowercase English letters.

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Determine if Two Strings Are Close

med
30 min
Try to solve the Determine if Two Strings Are Close problem.

Statement

Two strings are considered close if one can be transformed into the other by applying any sequence of the following operations:

  • Operation 11: Swap any two existing characters. For instance, abcde becomes aebcd.

  • Operation 22: Swap the frequencies of any two existing characters by transforming every occurrence of one existing character into another existing character, and vice versa. For instance, aacabb becomes bbcbaa by transforming all a characters to b and all b characters to a.

You may apply these operations on either string as many times as needed.

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

Constraints:

  • 1≤1 \leq word1.length, word2.length ≤105\leq 10^5

  • word1 and word2 contain only lowercase English letters.