https://programmers.co.kr/learn/courses/30/lessons/12981
function solution(n, words) {
let result = [];
let history = [words[0]];
let index = 0;
for(let i = 1; i < words.length; i++) {
if(history.includes(words[i]) || history[history.length-1].slice(-1) !== words[i].slice(0, 1)) {
if(i < n) {
result.push(i+1);
index = 1;
} else {
result.push(i - (n * Math.floor(i/n)) + 1);
index = Math.floor(i/n) + 1;
}
result.push(index);
break;
}
history.push(words[i]);
}
if(index === 0) {
result = [0, 0];
}
return result;
}
시간 초과될 줄 알았는데 통과해서 살짝 당황했지만 기분 좋당...( ͡° ͜ʖ ͡°)