본문 바로가기

코딩테스트187

[Programmers Test] (1회차 코딩테스트) No 1. BuildPyramid [문제 설명] 블록으로 피라미드 모양의 탑을 쌓으려고 합니다. 피라미드 모양의 탑은 꼭대기는 1개의 블록을 사용하고, 그 아래는 2개의 블록, 그 아래에는 3개의 블록의 방식으로 쌓습니다. n 층의 피라미드 모양의 탑을 쌓을 때, 필요한 블록의 수를 구하는 함수, solution을 완성해주세요. 예를 들어, 4층의 피라미드에는 총 10개의 블록이 필요합니다. > 4층에 사용되는 블록 수 1개 > 3층에 사용되는 블록 수 2개 > 2층에 사용되는 블록 수 3개 > 1층에 사용되는 블록 수 4개 > 피라미드에 사용되는 블록의 총수는 10개입니다. [입력 형식] - n은 1 이상 1,000 이하의 정수입니다. [출력 형식] - 피라미드 모양의 탑을 쌓는데 필요한 블록의 총수를 구합니다. /** * @param.. 2023. 1. 20.
[Programmers] (완전탐색) Lv 2. 피로도 https://school.programmers.co.kr/learn/courses/30/lessons/87946 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr const solution = (k, dungeons) => { let answer = 0; const visit = Array.from({ length: dungeons.length }, (_) => false); const dfs = (k, cnt) => { for (const i in dungeons) { const [need, consume] = dungeons[i]; if (!visit[.. 2023. 1. 18.
[Programmers] (탐욕법[Greedy]) Lv 2. 구명보트 https://school.programmers.co.kr/learn/courses/30/lessons/42885 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr function solution(people, limit) { var answer = 0; people.sort((a, b) => b - a); for (let i = 0, j = people.length - 1; i = people[i] + people[j]) { ++answer; --j; } else ++answer; } return answer; } GitHub : https://github.. 2023. 1. 17.
[Programmers] Lv 1. 콜라츠 추측 https://school.programmers.co.kr/learn/courses/30/lessons/12943 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr const solution = (num) => collatz(num, (acc = 0)); const collatz = (num, acc) => num === 1 ? (acc >= 500 ? -1 : acc) : collatz(cal(num), ++acc); const cal = (num) => (num % 2 ? num * 3 + 1 : num / 2); GitHub : https://githu.. 2023. 1. 17.
[LeetCode] (Linked List) Lv Easy. Delete Node in a Linked List https://leetcode.com/explore/interview/card/top-interview-questions-easy/93/linked-list/553/ Explore - LeetCode LeetCode Explore is the best place for everyone to start practicing and learning on LeetCode. No matter if you are a beginner or a master, there are always new topics waiting for you to explore. leetcode.com /** * Definition for singly-linked list. * function ListNode(val) { * this.val.. 2023. 1. 16.
[Programmers] Lv 1. 과일 장수 https://school.programmers.co.kr/learn/courses/30/lessons/135808 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr function solution(k, m, score) { var answer = 0; score = score .sort((a, b) => b - a) .filter( (e, index) => 1 2023. 1. 16.
[LeetCode] (Strings) Lv Easy. Reverse Integer https://leetcode.com/explore/interview/card/top-interview-questions-easy/127/strings/880/ Explore - LeetCode LeetCode Explore is the best place for everyone to start practicing and learning on LeetCode. No matter if you are a beginner or a master, there are always new topics waiting for you to explore. leetcode.com /** * @param {number} x * @return {number} */ function t1(x) { let result = parse.. 2023. 1. 16.
[LeetCode] (Array) Lv Easy. Best Time to Buy and Sell Stock II https://leetcode.com/explore/interview/card/top-interview-questions-easy/92/array/564/ Explore - LeetCode LeetCode Explore is the best place for everyone to start practicing and learning on LeetCode. No matter if you are a beginner or a master, there are always new topics waiting for you to explore. leetcode.com /** * @param {number[]} prices * @return {number} */ var maxProfit = function (price.. 2023. 1. 16.
[Programmers] Lv 1. 기사단원의 무기 https://school.programmers.co.kr/learn/courses/30/lessons/136798 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr function solution(number, limit, power) { let a = 0; for (let cur = 1; cur 2023. 1. 15.
[Programmers] Lv 1. 명예의 전당(1) https://school.programmers.co.kr/learn/courses/30/lessons/138477 프로그래머스 코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요. programmers.co.kr function solution(k, score) { var award = []; return score.reduce((a, element) => { if (k > award.length) { award.push(element); award.sort((a, b) => a - b); } else if (element >= award.at(0)) { award.push(element); award... 2023. 1. 15.