All problems
1168MediumHash TableStringBacktrackingCounting

Rows That Can Be Laid From the Tiles

Tracked in this browser only
Write code

Trains the technique from

LeetCode 1079Letter Tile Possibilities

This is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.

Same function shape, different story and different numbers.

A bag holds tiles, each stamped with one uppercase letter, given by tiles. Tiles may be laid out in a row in any order, using anywhere from one of them up to all of them.

Return how many different non-empty strings can be laid out. Two rows count as the same string when they read alike.

Examples

Example 1

Input
tiles = "AB"
Output
4

The rows are A, B, AB and BA.

Example 2

Input
tiles = "AA"
Output
2

The two tiles read alike, so the only rows are A and AA.

Example 3

Input
tiles = "ABC"
Output
15

Three rows of one tile, six of two tiles and six of all three.

Constraints

  • 1 <= tiles.length <= 7
  • tiles holds only uppercase English letters

The signature

The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.

Python
def num_tile_possibilities(tiles: str) -> int:
Java
public int numTilePossibilities(String tiles)
September 7
Apply