Letter Tile Possibilities

Medium Topics Company Tags

Each character in tiles labels a separate tile. Form nonempty strings by selecting and ordering some of the tiles, using each tile at most once. Return the number of distinct strings you can form. Tiles with the same letter do not make otherwise identical strings different.

Example 1:

Input: tiles = "AB"

Output: 4

Explanation: The four distinct nonempty strings are "A", "B", "AB", and "BA".

Example 2:

Input: tiles = "AAA"

Output: 3

Explanation: The only distinct strings are "A", "AA", and "AAA". Choosing different copies of the same letter does not create a new string.

Example 3:

Input: tiles = "ABA"

Output: 8

Explanation: The eight strings are "A", "B", "AA", "AB", "BA", "AAB", "ABA", and "BAA".

Constraints:

  • 1 <= tiles.length <= 7
  • Only uppercase English letters occur.


Topics

Company Tags

Please upgrade to NeetCode Pro to view company tags.