LeetCode - 150 - Task Scheduler

The problem You are given an array of CPU tasks, each labeled with a letter from A to Z, and a number n. Each CPU interval can be idle or allow the completion of one task. Tasks can be completed in any order, but there’s a constraint: there has to be a gap of at least n intervals between two tasks with the same label. Return the minimum number of CPU intervals required to complete all tasks. ...

August 19, 2025 · 5 min · Dmytro Chumakov

LeetCode - 150 - Kth Largest Element in an Array

The problem Given an integer array nums and an integer k, return the kth largest element in the array. Note that it is the kth largest element in the sorted order, not the kth distinct element. Can you solve it without sorting? Examples Input: nums = [3,2,1,5,6,4], k = 2 Output: 5 Input: nums = [3,2,3,1,2,4,5,5,6], k = 4 Output: 4 Constraints 1 <= k <= nums.length <= 10^5 -10^4 <= nums[i] <= 10^4 Explanation From the description of the problem we learn that we need to find the kth largest element from the given array. The kth element means if, for example, we had k = 1 then we would return the first largest element, or if we had k = 3 then we would return the third largest element. ...

August 15, 2025 · 2 min · Dmytro Chumakov

LeetCode - 150 - K Closest Points to Origin

The problem Given an array of points where points[i] = [xi, yi] represents a point on the X-Y plane and an integer k, return the k closest points to the origin (0, 0). The distance between two points on the X-Y plane is the Euclidean distance (i.e., √(x1 - x2)^2 + (y1 - y2)^2). You may return the answer in any order. The answer is guaranteed to be unique (except for the order that it is in). ...

August 13, 2025 · 4 min · Dmytro Chumakov

LeetCode - 150 - Last Stone Weight

The problem 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 together. Suppose the heaviest two stones have weights x and y with x <= y. The result of this smash is: If x == y, both stones are destroyed, and If x != y, the stone of weight x is destroyed, and the stone of weight y has new weight y - x. At the end of the game, there is at most one stone left. ...

August 11, 2025 · 4 min · Dmytro Chumakov

LeetCode - 150 - Kth Largest Element in a Stream

The problem You are part of a university admissions office and need to keep track of the kth highest test score from applicants in real-time. This helps to determine cut-off marks for interviews and admissions dynamically as new applicants submit their scores. You are tasked to implement a class which, for a given integer k, maintains a stream of test scores and continuously returns the kth highest test score after a new score has been submitted. More specifically, we are looking for the kth highest score in the sorted list of all scores. ...

August 9, 2025 · 4 min · Dmytro Chumakov