function solution(info, query) {
function getCombination(arr, score, map, start) {
const key = arr.join('');
if (Array.isArray(map[key])){
map[key].push(score);
}else{
map[key] = [score];
}
for (let i = start; i < arr.length; i++) {
let combiArr = arr.slice();
combiArr[i] = '-';
getCombination(combiArr, score, map, i + 1);
}
}
function binarySearch(arr, score) {
if (!arr) return 0;
let left = 0;
let right = arr.length;
while (left < right) {
let mid = Math.floor((left + right) / 2);
if (arr[mid] >= score) right = mid;
else left = mid + 1;
}
return arr.length - left;
}
const map = {};
for (let i = 0; i < info.length; i++) {
const infos = info[i].split(' ');
const score = infos.pop();
getCombination(infos, score, map, 0);
}
for (let key in map){
map[key].sort((a, b) => a - b);
}
const result = [];
for (let i = 0; i < query.length; i++) {
let queryString = query[i].replace(/ and /g, '').split(' ');
let queryScore = Number(queryString.pop());
queryString = queryString.join('');
let scoreIdx = binarySearch(map[queryString], queryScore);
result.push(scoreIdx);
}
return result;
}
// 시간초과 난 답. 시간 초과 나서 혹시 모르니까 continue를 남발했는데 진짜 바보 같다.
// function solution(info, query) {
// var answer = [];
// for (let i=0;i<query.length;i++){
// // 이게 대체 무슨 문제냐
// let [codingL, FBJob, JSyear, FoodandScore]=query[i].split(' and ').map(el=>el.trim())
// let [food, score]=FoodandScore.split(' ').map(el=>el.trim())
// score=parseInt(score)
// let count=0;
// for (let j=0;j<info.length;j++){
// let [codingL2, FBJob2, JSyear2, food2, score2]=info[j].split(' ').map((el)=>el.trim());
// score2=parseInt(score2)
// if (codingL==='-'||codingL2===codingL){
// if (FBJob==='-'||FBJob2===FBJob){
// if (JSyear==='-'||JSyear2===JSyear){
// if(food==='-'||food2===food){
// if (score2>=score){
// count+=1;
// }else{
// continue;
// }
// }else{
// continue;
// }
// }else{
// continue;
// }
// }else{
// continue;
// }
// }
// }
// answer.push(count)
// }
// return answer;
// }
https://velog.io/@shleecloud/kakao2021-%EC%88%9C%EC%9C%84-%EA%B2%80%EC%83%89-javascript