function solution(user_id, banned_id) {
var answer = 0
const isBanned = (uid, bid) => {
if(uid.length!==bid.length) return;
for(let i=0; i<bid.length; i++){
const b = bid[i];
const u = uid[i];
if(b==='*') continue;
if(b!==u) return false;
}
return true;
}
const bannable = banned_id.map(bid => {
const match = []
user_id.forEach((uid, i) => isBanned(uid, bid) && match.push(i))
return match;
})
const set = new Set()
const dfs = (depth, nodes) => {
const bannableUsers = bannable[depth]
if(depth===banned_id.length){
return set.add(nodes.join(''))
}
bannableUsers.forEach(bannableUser => {
const newNodes = [...nodes]
if(newNodes[bannableUser]) return
newNodes[bannableUser] = 1;
dfs(depth+1, newNodes);
})
}
dfs(0, Array(user_id.length).fill(0))
return set.size;
}
Level
프로그래머스 Lv3
Day
13일
kakao
2019 카카오 인턴십