Skip to content

Commit c779548

Browse files
Merge pull request #638 from eric-hjh/main
[황장현] 94차 라이브 코테 제출
2 parents bcbcb2c + ee18212 commit c779548

5 files changed

Lines changed: 134 additions & 35 deletions

File tree

live9/test93/문제2/황장현.js

Lines changed: 17 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,24 @@
1-
const alphabetValues = {
2-
B: 1,
3-
C: 2,
4-
D: 3,
5-
E: 4,
6-
F: 5,
7-
G: 6,
8-
H: 7,
9-
I: 8,
10-
J: 9,
11-
K: 10,
12-
L: 11,
13-
M: 13,
14-
N: 12,
15-
O: 12,
16-
P: 11,
17-
Q: 10,
18-
R: 9,
19-
S: 8,
20-
T: 7,
21-
U: 6,
22-
V: 5,
23-
W: 4,
24-
X: 3,
25-
Y: 2,
26-
Z: 1,
27-
};
28-
291
function solution(name) {
30-
let answer = 0;
2+
let moveCount = 0;
3+
let minMove = name.length - 1;
4+
315
for (let i = 0; i < name.length; i++) {
32-
if (name[i] === 'A') {
33-
answer += -1;
34-
} else {
35-
answer += alphabetValues[name[i]];
6+
const char = name[i];
7+
moveCount += Math.min(char.charCodeAt(0) - 65, 91 - char.charCodeAt(0));
8+
9+
let nextIdx = i + 1;
10+
while (nextIdx < name.length && name[nextIdx] === 'A') {
11+
nextIdx++;
3612
}
13+
14+
minMove = Math.min(
15+
minMove,
16+
i * 2 + (name.length - nextIdx),
17+
i + 2 * (name.length - nextIdx)
18+
);
3719
}
38-
answer += name.length;
39-
return answer;
20+
21+
return moveCount + minMove;
4022
}
4123

4224
// console.log(solution('JEROEN'));

live9/test93/문제3/황장현.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
function solution(routes) {
2+
routes.sort((a, b) => a[1] - b[1]);
3+
4+
let cameraCount = 0;
5+
let lastCameraPos = -30001;
6+
7+
for (let route of routes) {
8+
let [enter, exit] = route;
9+
10+
if (enter > lastCameraPos) {
11+
cameraCount++;
12+
lastCameraPos = exit;
13+
}
14+
}
15+
16+
return cameraCount;
17+
}
18+
19+
console.log(
20+
solution([
21+
[-20, -15],
22+
[-14, -5],
23+
[-18, -13],
24+
[-5, -3],
25+
])
26+
);

live9/test94/문제1/황장현.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
function solution(dirs) {
2+
let x = 0;
3+
let y = 0;
4+
5+
const visited = new Set();
6+
const directions = {
7+
U: [0, 1],
8+
D: [0, -1],
9+
L: [-1, 0],
10+
R: [1, 0],
11+
};
12+
13+
for (let dir of dirs) {
14+
const [dx, dy] = directions[dir];
15+
let nx = x + dx;
16+
let ny = y + dy;
17+
18+
if (nx < -5 || nx > 5 || ny < -5 || ny > 5) continue;
19+
20+
const path = `[${x},${y}]->[${nx},${ny}]`;
21+
22+
visited.add(path);
23+
24+
x = nx;
25+
y = ny;
26+
}
27+
28+
return visited.size;
29+
}
30+
31+
console.log(solution('ULURRDLLU'));
32+
// console.log(solution('LULLLLLLU'));

live9/test94/문제2/황장현.js

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
function solution(book_time) {
2+
const toMinutes = (time) => {
3+
const [hour, minute] = time.split(':').map(Number);
4+
return hour * 60 + minute;
5+
};
6+
7+
book_time.sort((a, b) => toMinutes(a[0]) - toMinutes(b[0]));
8+
9+
const rooms = [];
10+
11+
for (const [start, end] of book_time) {
12+
const startTime = toMinutes(start);
13+
const endTime = toMinutes(end) + 10;
14+
15+
let earliestRoomIndex = rooms.findIndex(
16+
(roomEndTime) => roomEndTime <= startTime
17+
);
18+
19+
if (earliestRoomIndex !== -1) {
20+
rooms[earliestRoomIndex] = endTime;
21+
} else {
22+
rooms.push(endTime);
23+
}
24+
25+
rooms.sort((a, b) => a - b);
26+
}
27+
28+
return rooms.length;
29+
}
30+
31+
console.log(
32+
solution([
33+
['15:00', '17:00'],
34+
['16:40', '18:20'],
35+
['14:20', '15:20'],
36+
['14:10', '19:20'],
37+
['18:20', '21:20'],
38+
])
39+
);

live9/test94/문제3/황장현.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
function solution(stones, k) {
2+
let min = 1;
3+
let max = 200000000;
4+
5+
while (min <= max) {
6+
const mid = Math.floor((min + max) / 2);
7+
let cnt = 0;
8+
for (let stone of stones) {
9+
if (stone - mid <= 0) cnt++;
10+
else cnt = 0;
11+
12+
if (cnt === k) break;
13+
}
14+
if (cnt === k) max = mid - 1;
15+
else min = mid + 1;
16+
}
17+
return min;
18+
}
19+
20+
console.log(solution([2, 4, 5, 3, 2, 1, 4, 2, 5, 1], 3));

0 commit comments

Comments
 (0)