Heap

    LeetCode / Heap / 502번 / IPO / JS

    더보기LeetCode가 IPO를 앞두고 자본을 최대화하기 위해 최대 k개의 프로젝트를 선택하여 완료하려고 한다.각 프로젝트는 특정 이익(profits)과 시작하기 위해 필요한 최소 자본(capital)을 가지고 있다.초기 자본(w)로 시작하여 프로젝트를 선택하고, 선택한 프로젝트의 이익을 총 자본에 추가한다.최대 k개의 프로젝트를 선택하여 최종 자본을 최대화하는 방법을 찾아야 한다.최종 최대 자본을 반환하면 되는 문제이다. /** * @param {number} k 선택할 프로젝트의 최대 개수 * @param {number} w 초기 자본 * @param {number[]} profits 순수 이익 * @param {number[]} capital 시작하기 위해 필요한 최소 자본 * @return {nu..

    LeetCode / Heap / 692번 / Top K Frequent Words / JS

    Top K Frequent Words - LeetCode Can you solve this real interview question? Top K Frequent Words - Given an array of strings words and an integer k, return the k most frequent strings. Return the answer sorted by the frequency from highest to lowest. Sort the words with the same frequenc leetcode.com 단어들이 들어있는 배열 words 배열과 정수인 k가 들어온다. words 배열에서 가장 많이 나온 단어들을 순서대로 k개만 반환..

    LeetCode / Heap / 1046번 / Last Stone Weight / JS

    Last Stone Weight - LeetCode Can you solve this real interview question? Last Stone Weight - You are given an array of integers stones where stones[i] is the weight of the ith stone. We are playing a game with the stones. On each turn, we choose the heaviest two stones and smash them leetcode.com 돌의 무게들이 배열로 들어온다. 그 중에서 가장 큰 두개의 돌의 무게를 x와 y라고 한다. 이때 x는 y이하이다. 만약 x와 y가 같다면..