Skip to content

Practice Make Number of Distinct Characters Equal

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Medium#2531
LeetCode Problem

Make Number of Distinct Characters Equal

Problem Statement

You are given two 0-indexed strings word1 and word2. A move consists of choosing two indices i and j such that 0 <= i < word1.length and 0 <= j < word2.length and swapping word1[i] with word2[j]. Return true if it is possible to get the number of distinct characters in word1 and word2 to be equal with exactly one move. Return false otherwise.

Source: Make Number of Distinct Characters Equal on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
word1 = "ac", word2 = "b"
Output
false

# Example 2

Input
word1 = "abcc", word2 = "aab"
Output
true

# Example 3

Input
word1 = "abcde", word2 = "fghij"
Output
true

Constraints

1 <= word1.length, word2.length <= 10^5
word1 and word2 consist of only lowercase English letters.

Related LeetCode Problems

Practice more problems similar to Make Number of Distinct Characters Equal.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.