You have n&nbsp;&nbsp;tiles, where each tile has one letter tiles[i] printed on it.

Return the number of possible non-empty sequences of letters you can make using the letters printed on those tiles.

&nbsp;
Example 1:

Input: tiles = "AAB"
Output: 8
Explanation: The possible sequences are "A", "B", "AA", "AB", "BA", "AAB", "ABA", "BAA".


Example 2:

Input: tiles = "AAABBC"
Output: 188


Example 3:

Input: tiles = "V"
Output: 1


&nbsp;
Constraints:


	1 &lt;= tiles.length &lt;= 7
	tiles consists of uppercase English letters.


class Solution:
    def numTilePossibilities(self, tiles: str) -> int:
        n= len(tiles)
        tiles=list(tiles)
        s1=set()
        for i in range(1,n+1):
            s1.update(permutations(tiles,i))
        return len(s1)
class Solution {
    private int result=0;
    public int numTilePossibilities(String tiles) {
        Map<Character,Integer> map = new HashMap<>();
        for(char c:tiles.toCharArray()){
            map.put(c,map.getOrDefault(c,0)+1);
        }
        find(map);
        return result-1;
    }
    public void find(Map<Character,Integer> map){
        result++;
        for(Map.Entry<Character,Integer> m:map.entrySet()){
            char c=m.getKey();
            int val =m.getValue();
            if(val>0){
                map.put(c,val-1);
                find(map);
                map.put(c,val);
            }
        }
    }
}
class Solution {
public:
    void recur(vector<string> &ans, string tiles, int index, int &res)
    {
        res++;

        for(int i=index; i<tiles.size(); i++)
        {
            if(i != index && tiles[i] == tiles[index])
                continue;
            swap(tiles[i], tiles[index]);
            recur(ans, tiles, index+1, res);
        }

    }
    
    int numTilePossibilities(string tiles) {
        
        vector<string> ans;
        sort(tiles.begin(), tiles.end());
        int res = 0;
        recur(ans, tiles, 0, res);
        return res - 1;
    }
};
//""This solution isn`t the best way but it`s simple""
 var numTilePossibilities = function(tiles) {
    return search(tiles);
};
// this function takes a state and check if it`s valid or !
// valid state is not null state and unique
// e.g ["","A","A"]=>is not valid state because is has null state and repeated
// values by contrast ["A"] is valid state
// !!state below is to check if state not null
const isValidState=(state="",res=[])=>!!state&&!res.includes(state);
// this function permutes tiles by backtracking
const search=(tiles="",state='',result=[])=>{
    if(isValidState(state,result))//check if the current state valid
        result.push(state)
    //loop through tiles and every time you push letter to state
    // the remaining tiles will decreased by one
    /**
     * ---e.g--
     * level 1 tiles=AAB state=""
     * it will loop through the tiles ;
     * now I am in index 0 push tiles[0] to state now state=A
     * by making this operation number of option tiles will be
     * decreased to newTiles="AB"
     * ...
     * ..
     * .
     * */
    for(let i=0;i<tiles.length;i++){
        state+=tiles[i];
        const newTiles=tiles.substring(0,i)+tiles.substring(i+1);
        search(newTiles,state,result)
        state=state.slice(0,state.length-1);
    }
    return result.length;
}
Letter Tile Possibilities