목록Sort (14)
N
https://leetcode.com/problems/maximum-units-on-a-truck/ Maximum Units on a Truck - LeetCode Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview. leetcode.com 정렬을 활용한 문제. 주어진 boxTypes 배열을 정렬하는데, boxTypes[1] 번째 요소의 내림차순으로 정렬을 해준다. 이후 for문을 이용해 truckSize가 채워지는 만큼 박스를 트럭에 채운다. 만약 truckSize - num이 0 이상이라면 모든 박스를 ..

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..
389. Find the Difference You are given two strings s and t. String t is generated by random shuffling string s and then add one more letter at a random position. Return the letter that was added to t. Example 1: Input: s = "abcd", t = "abcde" Output: "e" Explanation: 'e' is the letter that was added. Example 2: Input: s = "", t = "y" Output: "y" Example 3: Input: s = "a", t = "aa" Output: "a" Ex..
56. Merge Intervals Given an array of intervals where intervals[i] = [starti, endi], merge all overlapping intervals, and return an array of the non-overlapping intervals that cover all the intervals in the input. Example 1: Input: intervals = [[1,3],[2,6],[8,10],[15,18]] Output: [[1,6],[8,10],[15,18]] Explanation: Since intervals [1,3] and [2,6] overlaps, merge them into [1,6]. Example 2: Input..
56. Merge Intervals Given an array of intervals where intervals[i] = [starti, endi], merge all overlapping intervals, and return an array of the non-overlapping intervals that cover all the intervals in the input. Example 1: Input: intervals = [[1,3],[2,6],[8,10],[15,18]] Output: [[1,6],[8,10],[15,18]] Explanation: Since intervals [1,3] and [2,6] overlaps, merge them into [1,6]. Example 2: Input..
programmers.co.kr/learn/courses/30/lessons/42748 코딩테스트 연습 - K번째수 [1, 5, 2, 6, 3, 7, 4] [[2, 5, 3], [4, 4, 1], [1, 7, 3]] [5, 6, 3] programmers.co.kr function solution(array, commands) { let answer = []; commands.filter((val, index) => { answer.push( array.slice(commands[index][0] - 1, commands[index][1]).sort((a, b) => a - b)[ commands[index][2] - 1 ] ); }); return answer; }
programmers.co.kr/learn/courses/30/lessons/42576 코딩테스트 연습 - 완주하지 못한 선수 수많은 마라톤 선수들이 마라톤에 참여하였습니다. 단 한 명의 선수를 제외하고는 모든 선수가 마라톤을 완주하였습니다. 마라톤에 참여한 선수들의 이름이 담긴 배열 participant와 완주한 선수 programmers.co.kr 입력으로 받은 두 배열을 오름차순으로 정렬. 참가자의 인덱스에 위치한 이름과 완주한 선수의 인덱스에 위치한 이름이 같지 않으면 그 선수가 완주하지 못한 선수이다. function solution(participant, completion) { let answer = ''; participant.sort(); completion.sort(); for(let ..
programmers.co.kr/learn/courses/30/lessons/12910 코딩테스트 연습 - 나누어 떨어지는 숫자 배열 array의 각 element 중 divisor로 나누어 떨어지는 값을 오름차순으로 정렬한 배열을 반환하는 함수, solution을 작성해주세요. divisor로 나누어 떨어지는 element가 하나도 없다면 배열에 -1을 담아 반환하 programmers.co.kr filter 함수를 이용해 divisor로 나누어 떨어지는 수만 answer에 저장. 만약 answer가 비어있다면 [-1]을 리턴, 아니라면 sort를 이용해 오름차순으로 정렬해서 리턴한다. function solution(arr, divisor) { let answer = arr.filter((val) =..