classSolution{ fun numTilePossibilities(tiles: String): Int { val count = IntArray(26) { 0 } tiles.forEach { count[it - 'A']++ } fun backTrack(): Int { var res = 0 for (i in count.indices) { if (count[i] <= 0) { continue } res += 1 count[i]-- res += backTrack() count[i]++ } return res } return backTrack() } }