Skip to the code
cf.
+50 XP

#652 Distinct Badge Arrangements

hard

A profile page shows a row of achievement badges. Each badge is a lowercase letter in badges, and badges with the same letter look identical.

Write badgeArrangements(badges) that returns how many visibly different orders of the row exist, modulo 1000000007.

Example 1

Input: badges = "aab"
Output: 3

aab, aba, and baa. Swapping the two as looks the same.

Example 2

Input: badges = "abc"
Output: 6

All letters differ, so all 3! = 6 orders look different.

Constraints

  • 1 <= badges.length <= 10^5
  • badges contains lowercase letters only.
Saved in this browser

Run tries your code on the examples. Submit runs every test, including hidden edge cases, and solves the problem when they all pass.

Ctrl + Enter runs, Ctrl + Shift + Enter submits (⌘ on a Mac).