Practice Determine if Two Strings Are Close
Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.
Problem Statement
A move may swap two positions, or choose two characters already present and simultaneously exchange all occurrences of those two characters. Either move may be repeated on either input string. Return whether word1 and word2 can become equal through these operations.
Source: Determine if Two Strings Are Close on LeetCode. Use the original task for its coding environment and submissions.
Examples
# Example 1
Input
word1 = "abc", word2 = "bca"
Output
true
# Example 2
Input
word1 = "a", word2 = "aa"
Output
false
# Example 3
Input
word1 = "cabbba", word2 = "abbccc"
Output
true
Constraints
1 <= word1.length, word2.length <= 10^5
word1 and word2 contain only lowercase English letters.
Related LeetCode Problems
Practice more problems similar to Determine if Two Strings Are Close.
Review your practice with PhantomCodeAI
After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.