목록js (166)
N
https://programmers.co.kr/learn/courses/30/lessons/12982 코딩테스트 연습 - 예산 S사에서는 각 부서에 필요한 물품을 지원해 주기 위해 부서별로 물품을 구매하는데 필요한 금액을 조사했습니다. 그러나, 전체 예산이 정해져 있기 때문에 모든 부서의 물품을 구매해 줄 수는 programmers.co.kr 최대한 많은 부서에 예산을 줘야하기 때문에 주어진 d 배열을 오름차순으로 정렬한다. 이후 이진 탐색을 진행. 0 ~ mid 인덱스까지의 예산을 더하여 budget보다 작을 때까지의 front 값을 찾아 리턴하면 된다. const binarySearch = (d, mid, budget) => { let sum = 0; for(let i = 0; i budget){ r..
https://programmers.co.kr/learn/courses/30/lessons/64062?language=javascript 코딩테스트 연습 - 징검다리 건너기 [2, 4, 5, 3, 2, 1, 4, 2, 5, 1] 3 3 programmers.co.kr const binarySearch = (stones, mid, k) => { let count = 0; for(let i = 0; i { let front = 0; let back = 200000000; while(front
https://programmers.co.kr/learn/courses/30/lessons/72412 { const answer = []; const infoParsingData = new Map(); const queryParsingData = []; // info 데이터 파싱 for(let i = 0; i Array(2).fill("-")); const score = parseInt(data.splice(4)); for(let j = 0; j < 4; j++){ string[j][0] = data[j]; } for(const ..
51. N-Queens The n-queens puzzle is the problem of placing n queens on an n x n chessboard such that no two queens attack each other. Given an integer n, return all distinct solutions to the n-queens puzzle. You may return the answer in any order. Each solution contains a distinct board configuration of the n-queens' placement, where 'Q' and '.' both indicate a queen and an empty space, respecti..
77. Combinations Given two integers n and k, return all possible combinations of k numbers out of the range [1, n]. You may return the answer in any order. Example 1: Input: n = 4, k = 2 Output: [ [2,4], [3,4], [2,3], [1,2], [1,3], [1,4], ] Example 2: Input: n = 1, k = 1 Output: [[1]] Constraints: 1 [fixed, ...c]); result.push(...attached); }); return result; } const combine = (n, k) => { const ..
46. Permutations Given an array nums of distinct integers, return all the possible permutations. You can return the answer in any order. Example 1: Input: nums = [1,2,3] Output: [[1,2,3],[1,3,2],[2,1,3],[2,3,1],[3,1,2],[3,2,1]] Example 2: Input: nums = [0,1] Output: [[0,1],[1,0]] Example 3: Input: nums = [1] Output: [[1]] Constraints: 1
11. Container With Most Water Given n non-negative integers a1, a2, ..., an , where each represents a point at coordinate (i, ai). n vertical lines are drawn such that the two endpoints of the line i is at (i, ai) and (i, 0). Find two lines, which, together with the x-axis forms a container, such that the container contains the most water. Notice that you may not slant the container. Example 1: ..
1465. Maximum Area of a Piece of Cake After Horizontal and Vertical Cuts You are given a rectangular cake of size h x w and two arrays of integers horizontalCuts and verticalCuts where: horizontalCuts[i] is the distance from the top of the rectangular cake to the ith horizontal cut and similarly, and verticalCuts[j] is the distance from the left of the rectangular cake to the jth vertical cut. R..