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

LeetCode - 150 - Count Good Nodes in Binary Tree

The problem Given a binary tree root, a node X in the tree is named good if in the path from root to X there are no nodes with a value greater than X. Return the number of good nodes in the binary tree. Examples Input: root = [3,1,4,3,null,1,5] Output: 4 Explanation: Nodes in blue are good. Root Node (3) is always a good node. Node 4 -> (3,4) is the maximum value in the path starting from the root. Node 5 -> (3,4,5) is the maximum value in the path Node 3 -> (3,1,3) is the maximum value in the path. ...

August 7, 2025 · 3 min · Dmytro Chumakov

LeetCode - 150 - Binary Tree Right Side View

The problem Given the root of a binary tree, imagine yourself standing on the right side of it, return the values of the nodes you can see ordered from top to bottom. Examples Input: root = [1,2,3,null,5,null,4] Output: [1,3,4] Explanation: Input: root = [1,2,3,4,null,null,null,5] Output: [1,3,4,5] Explanation: Input: root = [1,null,3] Output: [1,3] Input: root = [] Output: [] Constraints The number of nodes in the tree is in the range [0, 100]. -100 <= Node.val <= 100 Explanation Let’s imagine that we have a person on the right side and if we look at the first example, we can see everything on the right side. ...

August 5, 2025 · 4 min · Dmytro Chumakov