




풀이
은찬
const solution = (play_time, adv_time, logs) => { let time = 0; let sum = 0; const calculateSecond = (h, m, s) => (h * 3600) + (m * 60) + s; const splitAndConvert = (time) => time.split(":").map((v) => parseInt(v)); const [ph, pm, ps] = splitAndConvert(play_time); const [ah, am, as] = splitAndConvert(adv_time); const playTime = calculateSecond(ph, pm, ps); const advTime = calculateSecond(ah, am, as); const imos = Array(playTime + 1).fill(0); const timeFormat = (time) => { const h = Math.floor(time / 3600); const m = Math.floor(time % 3600 / 60); const s = time % 3600 % 60; return `${h < 10 ? "0" : ""}${h}:${m < 10 ? "0" : ""}${m}:${s < 10 ? "0" : ""}${s}` } if(playTime === advTime){ return "00:00:00"; } for(const log of logs){ const [start, end] = log.split("-"); const [sh, sm, ss] = splitAndConvert(start); const [eh, em, es] = splitAndConvert(end); const startTime = calculateSecond(sh, sm, ss); const endTime = calculateSecond(eh, em, es); imos[startTime]++; imos[endTime]--; } for(let i = 1; i <= playTime; i++){ imos[i] += imos[i - 1]; } for(let i = 1; i <= playTime; i++){ imos[i] += imos[i - 1]; } sum = imos[advTime - 1]; for(let i = advTime - 1; i < playTime; i++){ const aTime = imos[i] - imos[i - advTime]; if(sum < aTime){ sum = aTime; time = i - advTime + 1; } } return timeFormat(time);; }
재영
const getSeconds = (time) => { const timeArr = time.split(":").map((val) => parseInt(val)); return timeArr[0] * 3600 + timeArr[1] * 60 + timeArr[2] * 1; }; const parseTime = (num) => { const hours = parseInt(num / 3600); const minutes = parseInt((num - hours * 3600) / 60); const seconds = num % 60; const convertFormat = (number) => (number < 10 ? `0${number}` : number); return `${convertFormat(hours)}:${convertFormat(minutes)}:${convertFormat( seconds )}`; }; const solution = (play_time, adv_time, logs) => { const playSeconds = getSeconds(play_time); const advSeconds = getSeconds(adv_time); const arr = new Array(playSeconds + 1).fill(0); logs.forEach((log) => { const [start, end] = log.split("-").map((time) => getSeconds(time)); arr[start] += 1; arr[end] -= 1; }); for (let i = 1; i <= playSeconds; i += 1) { arr[i] += arr[i - 1]; } for (let i = 1; i <= playSeconds; i += 1) { arr[i] += arr[i - 1]; } let acc = arr[advSeconds]; let result = 0; for (let i = 0; i <= playSeconds - advSeconds; i += 1) { if (arr[i + advSeconds] - arr[i] > acc) { acc = arr[i + advSeconds] - arr[i]; result = i + 1; } } return parseTime(result); };