본문 바로가기

Coding Test96

[Java] (프로그래머스 Level 2) 뉴스 클러스터링 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr 내 풀이 import java.util.*; class Solution { public int solution(String str1, String str2) { // 2글자씩 자르기 Map map1 = getSubstringMap(str1.toLowerCase()); Map map2 = getSubstringMap(str2.toLowerCase()); // map1, map2의 키값을 각각 순회하면서 map3 map4를 만든다. 이때 map3는 min값으로, map4는 max값으로 만든다. Map minMap.. 2023. 4. 13.
[Python] (프로그래머스 Level 3) 이중우선순위큐 [Python] (프로그래머스 Level 3) 이중우선순위큐 내 풀이 from heapq import heapify, heappush, heappop, nlargest def solution(operations): heap = [] heapify(heap) for operation in operations: [char, value] = operation.split(' ') if char == 'I': heappush(heap, int(value)) else: if len(heap) > 0: if value == '1': heap = nlargest(len(heap), heap)[1:] heapify(heap) else: heappop(heap) if heap: .. 2023. 2. 12.
[Python] (프로그래머스 Level 2) 더 맵게 [Python] (프로그래머스 Level 2) 더 맵게 내 풀이 import heapq def solution(scoville, K): heap = scoville heapq.heapify(scoville) count = 0 while True: min_val = heapq.heappop(heap) if min_val >= K: return count if len(heap) < 1: return -1 min_val2 = heapq.heappop(heap) heapq.heappush(heap, min_val + min_val2 *2) count += 1 return count JS로 공부할 때 Heap 구현은 해보았지만… 사용해서 문제를 풀어볼 엄두는 안나던데, python으로 하니 간단하게 import .. 2023. 2. 12.
M사 코테 후기, 기록 (23.02.12) 코테 후기 m사 코테를 봤다. 구현 문제 3개가 나왔는데, 난이도는 그렇게 어렵지 않았다. 프로그래머스로 따지면 Level 1, 3개라고 보면될듯. 3시간 20분이 주어졌는데, 1시간30분 정도에 끝낸것 같다. 사실 제출하면 끝인줄 모르고 프로그래머스처럼 테케 더 보고싶어서 제출누르자마자 더이상 변경이 불가해서 당황스럽더라… 아쉽게도 처음으로 푼 문제는 0점을 맞았다… 다른 문제들에 비해 좀 더 경솔하게 제출을 눌러서 그런것 같다. Codility에서 쳐서 점수를 바로 알려줬는데 결과는 생각보다 못나왔다… 구현 3문제인걸 보니 스타트업은 확실히 어려운 알고리즘을 원하기보단 실제로 구현하고 일할 수 있는 사람인지 확인하는 것 같다. (일정 내에 구현을 마무리 할 수 있는 기본적인 코딩을 할 줄 아는지) 앞.. 2023. 2. 12.
[Javascript] (LeetCode) 17. Letter Combinations of a Phone Number (Medium) [Javascript] (LeetCode Medium) 17. Letter Combinations of a Phone Number 💡 구글에 Javascript 풀이가 많이 없거나, 배운 점이 있으면 포스팅합니다. 내 풀이 /** * @param {string} digits * @return {string[]} */ //숫자들이 주어진다. // 숫자들은 각 후보가 주어진다. // 숫자들을 돌면서 어떤 후보가 뽑힐수있는지 모든 경우의 수를 잡는다. const letterMap = ['','','abc', 'def', 'ghi', 'jkl', 'mno', 'pqrs', 'tuv', 'wxyz' ] var letterCombinations = function(digits) { const result = [] .. 2023. 1. 1.
[Javascript] (LeetCode Medium) 841. Keys and Rooms 💡 구글에 Javascript 풀이가 많이 없거나, 배운 점이 있으면 포스팅합니다. 내 풀이 /** * @param {number[][]} rooms * @return {boolean} */ var canVisitAllRooms = function(rooms) { const visitedSet = new Set([0]) const keys = [0] let keyIndex = 0 while (keyIndex { if (!keys.includes(key)) { keys.push(key) } }) visitedSet.add(visiting) keyIndex++ } r.. 2022. 12. 21.
[Javascript] (프로그래머스 level 2) n^2 배열 자르기 💡 구글에 Javascript 풀이가 많이 없거나, 배운 점이 있으면 포스팅합니다. 내 풀이 // 최대 차수 n까지 // 해당 차수의 // 행 채우기 // 열 채우기 function solution(n, left, right) { const arr = Array(n).fill().map((x) => Array(n)) for (let k = 0; k < n; k++) { arr[k][k] = k + 1 for (let i = 0; i < k; i++) { arr[k][i] = k + 1 arr[i][k] = k + 1 } } const firstOrder = arr.flat() return firstOrder.slice(left, right + 1) } 위와 같이 하면 로직은 맞다. 하지만 채점 하면 메모.. 2022. 12. 15.
[Javascript] (프로그래머스 level 2) 튜플 [Javascript] (프로그래머스 level 2) 튜플 💡 구글에 Javascript 풀이가 많이 없거나, 배운 점이 있으면 포스팅합니다. 내 풀이 function solution(s) { // {가 시작되면 }가 나올때까지 temp에 담는다. // 이temp를 temps에 담는다. const temps = []; for (let i = 1; i a.length - b.length) const ans.. 2022. 11. 22.
[Javascript] (프로그래머스 level 2) 캐시 [Javascript] (프로그래머스 level 2) 캐시 💡 구글에 Javascript 풀이가 많이 없거나, 배운 점이 있으면 포스팅합니다. 내 풀이 function solution(cacheSize, cities) { let time = 0; const cache = []; const isFull = () => cache.length >= cacheSize; const isCached = (city) => cache.indexOf(city) !== -1; const cacheHitTime = () => time += 1; const cacheHit = (city) => { const indexOfCachedData = cache.indexOf(city) cache.splice(indexOfCached.. 2022. 11. 22.
[Javascript] (프로그래머스 level 2) h-index [Javascript] (프로그래머스 level 2) h-index 💡 구글에 Javascript 풀이가 많이 없거나, 배운 점이 있으면 포스팅합니다. 내 풀이 function solution(citations) { citations.sort((a, b) => b - a) let count = 0; for (let i = 0; i citations[i]) { return count } } return count } 배운 점, 느낀 점 쉬운문제인데 1시간 30분에 걸쳐서 풀었습니다. 로직상 맞는것같은데 계속 틀려서 결국 구글링해서 힌트를 얻어 풀었습니다. 뭐때문에 이리 오래걸.. 2022. 11. 22.