[JavaScript] 그래프 알고리즘
인접한 노드를 탐색하는 자료구조로, DFS를 이용하여 탐색한다. BFS로도 구현할 수 있지만 내가 DFS가 익숙하기에...function dfs(graph, visited, node) { if (visited[node]) return; visited[node] = true; console.log("Visiting:", node); for (let neighbor of graph[node]) { dfs(graph, visited, neighbor); }}// 예시const graph = { 0: [1, 2], 1: [0, 3], 2: [0, 4], 3: [1], 4: [2]};const visited = Array(Object.keys(graph).length).fill(false)..
2025. 5. 9.
[JavaScript/알고리즘] CountDiv
오랜만에 다시 하는 코딜리티...A와 B 사이에 K로 나눴을 때 몫이 0이 되는 수가 몇 개인지 세는 문제입니다. https://app.codility.com/demo/results/trainingGDW5F8-WJ7/ Test results - CodilityWrite a function: function solution(A, B, K); that, given three integers A, B and K, returns the number of integers within the range [A..B] that are divisible by K, i.e.: { i : A ≤ i ≤ B, i mod K = 0 } For example, for A = 6, B = 11 and K = 2, your fapp..
2025. 3. 1.
[JavaScript/알고리즘] CyclicRotation (feat. 테스트 케이스)
Lesson 2 (Arrays) - CyuclicRotation(Easy) Test results - CodilityAn array A consisting of N integers is given. Rotation of the array means that each element is shifted right by one index, and the last element of the array is moved to the first place. For example, the rotation of array A = [3, 8, 9, 7, 6] is [6, 3, 8, 9,app.codility.com점수: 62/100 일단 코딜리티는 문제를 제출하면 코드 수정을 못하더군요.테스트 케이스를 추가하는 능력도 중..
2025. 1. 4.