-
Notifications
You must be signed in to change notification settings - Fork 0
/
solution.js
58 lines (43 loc) · 1.03 KB
/
solution.js
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
const readline = require('readline');
let inputString = []
let currentLine = 0;
let i = 0;
let max = 0;
const rl = readline.createInterface({
input : process.stdin,
output : process.stdout
});
rl.question('# Elements: ', (elements) => {
inputString.push(elements.replace(/\s\s+/g, ' '));
max = elements;
});
rl.on('line', (el) => {
i++;
inputString.push(el.replace(/\s\s+/g, ' '));
if(i == max){
rl.close();
}
});
rl.on('close', () => {
main();
});
const readLine = () => {
return inputString[currentLine++];
}
const main = () => {
inputString.shift();
inputString.forEach(item => {
let n = item.split(' ')[0];
let top = item.split(' ')[1];
let max = 0;
for(let i=1; i <= n; i++){
for(let j=i+1; j <= n; j++){
let bit = i&j;
if(bit >= max && bit < top){
max = bit;
}
}
}
console.log({max});
});
}