#2514

Count Anagrams

master · 1795 · lc hard +32 · verified · 37.1% accepted · 473 likes · top 15%

Description

Given a string s of space-separated words, a string is an anagram of s if each of its words is a permutation of the corresponding word in s (preserving word positions). Return the count of distinct such anagrams modulo 109 + 7.

Example 1:

Input: s = "too hot"
Output: 18
Explanation: Some of the anagrams of the given string are "too hot", "oot hot", "oto toh", "too toh", and "too oht".

Example 2:

Input: s = "aa"
Output: 1
Explanation: There is only one anagram possible for the given string.

Code

1
2
3