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

LeetCode - 150 - Balanced Binary Tree

The problem Given a binary tree, determine if it is height-balanced. A height-balanced binary tree is a binary tree in which the depth of the two subtrees of every node never differs by more than one. Examples Input: root = [3,9,20,null,null,15,7] Output: true Input: root = [1,2,2,3,3,null,null,4,4] Output: false Input: root = [] Output: true Constraints The number of nodes in the tree is in the range [0, 5000]. -10^4 <= Node.val <= 10^4 Explanation From the description of the problem, we learn that we need to find if the tree is height-balanced, and that we can do it by determining if the difference between the height of every single node in the left and right subtrees is no more than 1. ...

July 30, 2025 · 4 min · Dmytro Chumakov