Greedy

    LeetCode / Greedy / 621번 / Task Scheduler / JS

    Task Scheduler - LeetCode Can you solve this real interview question? Task Scheduler - Given a characters array tasks, representing the tasks a CPU needs to do, where each letter represents a different task. Tasks could be done in any order. Each task is done in one unit of time. F leetcode.com 해야하는 작업들의 리스트와 n이 주어진다. 여기서 n은 같은 작업을 잇따라 해야할 시에 중간에 반드시 텀을 둬야하는 시간이다.(유휴시간) 예..

    LeetCode / Greedy / 2131번 / Longest Palindrome by Concatenating Two Letter Words / JS

    Longest Palindrome by Concatenating Two Letter Words - LeetCode Can you solve this real interview question? Longest Palindrome by Concatenating Two Letter Words - You are given an array of strings words. Each element of words consists of two lowercase English letters. Create the longest possible palindrome by selecting leetcode.com words 리스트에서 단어들을 뽑아 조합해서 가장 긴 팰린드롬(좌우대칭)..

    LeetCode / Greedy / 409번 / Longest Palindrome / JS

    Longest Palindrome - LeetCode Can you solve this real interview question? Longest Palindrome - Given a string s which consists of lowercase or uppercase letters, return the length of the longest palindrome that can be built with those letters. Letters are case sensitive, for example, leetcode.com 주어진 문자열의 문자들로 만들 수 있는 문자열 중 가장 긴 팰린드롬 문자열을 만들었을 때 그 길이가 몇인지 반환하면 되는 문제이다. * ..

    LeetCode / Greedy / 121번 / Best Time to Buy and Sell Stock / JS

    Best Time to Buy and Sell Stock - LeetCode Can you solve this real interview question? Best Time to Buy and Sell Stock - You are given an array prices where prices[i] is the price of a given stock on the ith day. You want to maximize your profit by choosing a single day to buy one stock and choosin leetcode.com 당일의 주가들이 배열로 주어진다. 언제 매수를 해서 언제 매도를 하면 가장 큰 수익을 낼 수 있는지 확인한 후..

    백준 / 그리디 / 1449번 / 수리공 항승 / JS

    문제 항승이는 품질이 심각하게 나쁜 수도 파이프 회사의 수리공이다. 항승이는 세준 지하철 공사에서 물이 샌다는 소식을 듣고 수리를 하러 갔다. 파이프에서 물이 새는 곳은 신기하게도 가장 왼쪽에서 정수만큼 떨어진 거리만 물이 샌다. 항승이는 길이가 L인 테이프를 무한개 가지고 있다. 항승이는 테이프를 이용해서 물을 막으려고 한다. 항승이는 항상 물을 막을 때, 적어도 그 위치의 좌우 0.5만큼 간격을 줘야 물이 다시는 안 샌다고 생각한다. 물이 새는 곳의 위치와, 항승이가 가지고 있는 테이프의 길이 L이 주어졌을 때, 항승이가 필요한 테이프의 최소 개수를 구하는 프로그램을 작성하시오. 테이프를 자를 수 없고, 테이프를 겹쳐서 붙이는 것도 가능하다. 입력 첫째 줄에 물이 새는 곳의 개수 N과 테이프의 길이 ..

    백준 / 그리디(Greedy) / 2217번 / 로프 / JS

    문제 N(1 ≤ N ≤ 100,000)개의 로프가 있다. 이 로프를 이용하여 이런 저런 물체를 들어올릴 수 있다. 각각의 로프는 그 굵기나 길이가 다르기 때문에 들 수 있는 물체의 중량이 서로 다를 수도 있다. 하지만 여러 개의 로프를 병렬로 연결하면 각각의 로프에 걸리는 중량을 나눌 수 있다. k개의 로프를 사용하여 중량이 w인 물체를 들어올릴 때, 각각의 로프에는 모두 고르게 w/k 만큼의 중량이 걸리게 된다. 각 로프들에 대한 정보가 주어졌을 때, 이 로프들을 이용하여 들어올릴 수 있는 물체의 최대 중량을 구해내는 프로그램을 작성하시오. 모든 로프를 사용해야 할 필요는 없으며, 임의로 몇 개의 로프를 골라서 사용해도 된다. 입력 첫째 줄에 정수 N이 주어진다. 다음 N개의 줄에는 각 로프가 버틸 수..