Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 17 additions & 35 deletions live9/test93/문제2/황장현.js
Original file line number Diff line number Diff line change
@@ -1,42 +1,24 @@
const alphabetValues = {
B: 1,
C: 2,
D: 3,
E: 4,
F: 5,
G: 6,
H: 7,
I: 8,
J: 9,
K: 10,
L: 11,
M: 13,
N: 12,
O: 12,
P: 11,
Q: 10,
R: 9,
S: 8,
T: 7,
U: 6,
V: 5,
W: 4,
X: 3,
Y: 2,
Z: 1,
};

function solution(name) {
let answer = 0;
let moveCount = 0;
let minMove = name.length - 1;

for (let i = 0; i < name.length; i++) {
if (name[i] === 'A') {
answer += -1;
} else {
answer += alphabetValues[name[i]];
const char = name[i];
moveCount += Math.min(char.charCodeAt(0) - 65, 91 - char.charCodeAt(0));

let nextIdx = i + 1;
while (nextIdx < name.length && name[nextIdx] === 'A') {
nextIdx++;
}

minMove = Math.min(
minMove,
i * 2 + (name.length - nextIdx),
i + 2 * (name.length - nextIdx)
);
}
answer += name.length;
return answer;

return moveCount + minMove;
}

// console.log(solution('JEROEN'));
Expand Down
26 changes: 26 additions & 0 deletions live9/test93/문제3/황장현.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
function solution(routes) {
routes.sort((a, b) => a[1] - b[1]);

let cameraCount = 0;
let lastCameraPos = -30001;

for (let route of routes) {
let [enter, exit] = route;

if (enter > lastCameraPos) {
cameraCount++;
lastCameraPos = exit;
}
}

return cameraCount;
}

console.log(
solution([
[-20, -15],
[-14, -5],
[-18, -13],
[-5, -3],
])
);
32 changes: 32 additions & 0 deletions live9/test94/문제1/황장현.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
function solution(dirs) {
let x = 0;
let y = 0;

const visited = new Set();
const directions = {
U: [0, 1],
D: [0, -1],
L: [-1, 0],
R: [1, 0],
};

for (let dir of dirs) {
const [dx, dy] = directions[dir];
let nx = x + dx;
let ny = y + dy;

if (nx < -5 || nx > 5 || ny < -5 || ny > 5) continue;

const path = `[${x},${y}]->[${nx},${ny}]`;

visited.add(path);

x = nx;
y = ny;
}

return visited.size;
}

console.log(solution('ULURRDLLU'));
// console.log(solution('LULLLLLLU'));
39 changes: 39 additions & 0 deletions live9/test94/문제2/황장현.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
function solution(book_time) {
const toMinutes = (time) => {
const [hour, minute] = time.split(':').map(Number);
return hour * 60 + minute;
};

book_time.sort((a, b) => toMinutes(a[0]) - toMinutes(b[0]));

const rooms = [];

for (const [start, end] of book_time) {
const startTime = toMinutes(start);
const endTime = toMinutes(end) + 10;

let earliestRoomIndex = rooms.findIndex(
(roomEndTime) => roomEndTime <= startTime
);

if (earliestRoomIndex !== -1) {
rooms[earliestRoomIndex] = endTime;
} else {
rooms.push(endTime);
}

rooms.sort((a, b) => a - b);
}

return rooms.length;
}

console.log(
solution([
['15:00', '17:00'],
['16:40', '18:20'],
['14:20', '15:20'],
['14:10', '19:20'],
['18:20', '21:20'],
])
);
20 changes: 20 additions & 0 deletions live9/test94/문제3/황장현.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
function solution(stones, k) {
let min = 1;
let max = 200000000;

while (min <= max) {
const mid = Math.floor((min + max) / 2);
let cnt = 0;
for (let stone of stones) {
if (stone - mid <= 0) cnt++;
else cnt = 0;

if (cnt === k) break;
}
if (cnt === k) max = mid - 1;
else min = mid + 1;
}
return min;
}

console.log(solution([2, 4, 5, 3, 2, 1, 4, 2, 5, 1], 3));