LeetCode 124: Binary Tree Maximum Path Sum

Let’s solve LeetCode problem 124: Binary Tree Maximum Path Sum. The instructions are as follows: A path in a binary tree is a sequence of nodes where each pair of adjacent nodes in the sequence has an edge connecting them. A node can only appear in the sequence at most once. Note that the path does not need to pass through the root. The path sum of a path is the sum of the node’s values in the path. Given the root of a binary tree, return the maximum path sum of any non-empty path. ...

January 5, 2026 · 6 min · David Nabergoj

LeetCode 201: Bitwise AND of Numbers Range

Let’s solve LeetCode problem 201: Bitwise AND of Numbers Range. The instructions are as follows: Given two integers left and right that represent the range [left, right], return the bitwise AND of all numbers in this range, inclusive. Constraints: 0 <= left <= right <= 2^31 - 1 Let’s dive in! Looking at the common binary prefix Let \(l\) and \(r\) denote left and right, respectively. I’ll denote binary strings with 0b..., for example 5 can be written as 0b101. ...

January 4, 2026 · 5 min · David Nabergoj

LeetCode 347: Top K Frequent Elements

Let’s solve LeetCode problem 347: Top K Frequent Elements. The instructions are as follows: Given an integer array nums and an integer \(k\), return the \(k\) most frequent elements. You may return the answer in any order. Constraints: 1 <= nums.length <= 10^5 -10^4 <= nums[i] <= 10^4 \(k\) is in the range [1, the number of unique elements in the array]. It is guaranteed that the answer is unique. I solved this problem on NeetCode as well. The goal was to find a solution in \(O(n)\) time and space, where \(n\) is the length of nums. I’ll be showing this solution here. Even though some solutions that take \(O(n\log n)\) time are faster for LeetCode leaderboards, this solution will scale a bit better. Let’s dive in! ...

January 2, 2026 · 5 min · David Nabergoj

LeetCode 61: Rotate List

Let’s solve LeetCode problem 61: Rotate List. The instructions are as follows: Given the head of a linked list, rotate the list to the right by \(k\) places. Constraints: The number of nodes in the list is in the range [0, 500] -100 <= Node.val <= 100 0 <= k <= 2 * 10^9 Let’s dive in! Recalling array rotations In a recent post, I solved this exact problem for arrays (LeetCode problem 189). The method was a triple-reversal procedure: ...

January 2, 2026 · 5 min · David Nabergoj

LeetCode 55: Jump Game

Let’s solve LeetCode problem 55: Jump Game. The instructions are as follows: You are given an integer array nums. You are initially positioned at the array’s first index, and each element in the array represents your maximum jump length at that position. Return true if you can reach the last index, or false otherwise. Constraints: 1 <= nums.length <= 10^4 0 <= nums[i] <= 10^5 I solved this in two ways: a less efficient approach using dynamic programming, and a very fast greedy method. Let’s dive in! ...

January 1, 2026 · 4 min · David Nabergoj