a game of dominos consists of 28 domino tiles. between 0 and 6 dots appear at each end of every tile. Tiles can be reversed during the game, so the tile showing "2-3" can be played as "3-2". You are given a list of N unique domino tiles. Your task is to find any domino tile not on the list and return it in the format "X-Y", where X and Y are digit representing the number of dots on each end of the tile.
given an array of N strings representing unique domino tiles, returns a string representing any tile which is not in the Array A
Given { "0-0", "0-1", "1-2", "2-3"} -> one of missing tiles would be "0-3".
mine
function solution(A) {
let group = new Set();
let result = '';
A.forEach((el) => {
let reversedTile = el.charAt(2) + "-" + el.charAt(0);
group.add(el);
group.add(reversedTile);
})
for(let i = 0; i <= 6; i++) {
for(let j = 0; j <= 6; j++) {
let tile = i + "-" + j;
if(!group.has(tile)) {
result = tile;
break;
}
}
}
return result;
}
let output = solution(["0-0", "0-1", "1-2", "2-3"]);
console.log(output)
'Algorithm & World Class' 카테고리의 다른 글
(Algorithm) Microsoft Online Assessment Questions (0) | 2022.06.13 |
---|---|
(프로그래머스 LV.2) 방문 길이 구하기 (0) | 2022.04.23 |
[알고리즘] isIsogram (0) | 2022.04.15 |
[알고리즘] 06_[순열] 새로운 치킨 소스 레시피 (0) | 2021.11.11 |
[알고리즘] 05_[중복순열] 가위바위보 (0) | 2021.11.10 |