
[LeetCode] 2462. Total Cost to Hire K Workers, Medium

·
CodingTest/LeetCode
1. 문제각 사람 별 고용 비용을 담은 costs 배열이 주어지고, 사람을 고용하는 횟수 k와 선택할 수 있는 사람 수 candidates가 주어질 때, 최소 비용으로 사람을 고용하라.candidates는 costs 배열의 앞과 뒤에서 동시에 선택하여, 최소 비용인 사람을 선택해 고용한다.2. 해결class MinHeap { private heap: number[]; constructor() { this.heap = []; } getLeftChildIndex = (parentIndex) => parentIndex * 2 + 1; getRightChildIndex = (parentIndex) => parentIndex * 2 + 2; getParentIndex ..