-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path72412.js
More file actions
102 lines (91 loc) · 2.94 KB
/
72412.js
File metadata and controls
102 lines (91 loc) · 2.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
function solution(info, query) {
const database={};
for(let i=0; i<info.length; i++){
const temp = info[i].split(" ");
if(database[[temp[0],temp[1],temp[2],temp[3]]]){
database[[temp[0],temp[1],temp[2],temp[3]]].push(parseInt(temp[4]));
}
else
database[[temp[0],temp[1],temp[2],temp[3]]]=[parseInt(temp[4])]
}
for(x in database)
database[x].sort((a,b)=>a-b);
let answer = [];
for(let i=0; i<query.length; i++){
let temp = query[i].split(" ");
let search = [];
if(temp[0]==='-'){
search.push(['cpp'])
search.push(['java']);
search.push(['python']);
}
else{
search.push([temp[0]]);
}
if(temp[2]==='-'){
let tempSearch=[]
for(let j=0; j<search.length; j++){
tempSearch.push([...search[j],'backend']);
tempSearch.push([...search[j],'frontend']);
}
search = tempSearch;
}
else{
for(let j=0; j<search.length; j++){
search[j]=[...search[j],temp[2]];
}
}
if(temp[4]==='-'){
let tempSearch=[]
for(let j=0; j<search.length; j++){
tempSearch.push([...search[j],'junior']);
tempSearch.push([...search[j],'senior']);
}
search = tempSearch;
}
else{
for(let j=0; j<search.length; j++){
search[j]=[...search[j],temp[4]];
}
}
if(temp[6]==='-'){
let tempSearch=[]
for(let j=0; j<search.length; j++){
tempSearch.push([...search[j],'chicken']);
tempSearch.push([...search[j],'pizza']);
}
search = tempSearch;
}
else{
for(let j=0; j<search.length; j++){
search[j]=[...search[j],temp[6]];
}
}
let count=0;
for(let j=0; j<search.length; j++){
let tempDatabase = database[search[j]];
if(!tempDatabase) continue;
let start = 0;
let end = tempDatabase.length-1;
let mid = 0;
let num = parseInt(temp[7]);
while(start<end){
mid = Math.floor((end+start)/2);
if(tempDatabase[mid]>num){
end=mid-1;
}
else if(tempDatabase[mid]<num)
start=mid+1;
else if(tempDatabase[mid]==num){
start = mid;
break;
}
}
while(tempDatabase[start]>=num || start>=tempDatabase.length)
start--;
count+=tempDatabase.length-start-1;
}
answer.push(count)
}
return answer;
}