Level
프로그래머스 Lv3
 
function solution(user_id, banned_id) {
    var answer = 0;
    const isBanned = (user, bannedId) => {
        if(user.length!==bannedId.length) return false;
        
        for(let i=0; i<bannedId.length; i++){
            if(bannedId[i] === '*') continue;
            if(bannedId[i] !== user[i]) return false;
        }
        
        return true;
    }
    
    const duplicate = new Set();
    let ans=0;
    
    const dfs = (depth, path) => {
        if(depth===banned_id.length){
            const pathKey = path.join('');

            if(!duplicate.has(pathKey)){
              duplicate.add(pathKey);
              ans++;
            }
            
            return;
        }
        
        for(let i=0; i<user_id.length; i++){
            if(path[i] || !isBanned(user_id[i], banned_id[depth])) continue;
                 
            const newPath = [...path];
            newPath[i] = 1;
            
            dfs(depth+1, newPath);
        }
    };
    dfs(0, Array(user_id.length).fill(0));
    
    return ans;
}