Skip to content

Commit 9afb746

Browse files
author
Eric
committed
89차 1번 문제풀이
1 parent 949df2d commit 9afb746

1 file changed

Lines changed: 35 additions & 0 deletions

File tree

live8/test89/문제1/황장현.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
const input = require('fs')
2+
.readFileSync(process.platform === 'linux' ? '/dev/stdin' : './input.txt')
3+
.toString()
4+
.trim()
5+
.split('\n')
6+
.map((el) => el.split(' ').map(Number));
7+
8+
function solution(input) {
9+
const N = input[0][0];
10+
const elemets = input
11+
.slice(1)
12+
.flat()
13+
.sort((a, b) => a - b);
14+
15+
let answer = 4;
16+
17+
for (let i = 0; i < N; i++) {
18+
let start = i;
19+
let end = N - 1;
20+
21+
while (start < end) {
22+
if (elemets[end] - elemets[start] > 4) {
23+
end--;
24+
} else {
25+
const temp = 4 - (end - start);
26+
answer = Math.min(answer, temp);
27+
break;
28+
}
29+
}
30+
}
31+
32+
return answer;
33+
}
34+
35+
console.log(solution(input));

0 commit comments

Comments
 (0)