Skip to content

Practice Count Anagrams

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

Hard#2514
LeetCode Problem

Count Anagrams

Problem Statement

You are given a string s containing one or more words. Every consecutive pair of words is separated by a single space ' '. A string t is an anagram of string s if the ith word of t is a permutation of the ith word of s. Return the number of distinct anagrams of s. Since the answer may be very large, return it modulo 10^9 + 7.

Source: Count Anagrams on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
s = "too hot"
Output
18

# Example 2

Input
s = "aa"
Output
1

Constraints

1 <= s.length <= 10^5
s consists of lowercase English letters and spaces ' '.
There is single space between consecutive words.

Related LeetCode Problems

Practice more problems similar to Count Anagrams.

Review your practice with PhantomCodeAI

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