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

LeetCode 122: Best Time to Buy and Sell Stock II

Let’s solve LeetCode problem 122: Best Time to Buy and Sell Stock II. The instructions are as follows: You are given an integer array prices where prices[i] is the price of a given stock on the \(i\)-th day. On each day, you may decide to buy and/or sell the stock. You can only hold at most one share of the stock at any time. However, you can sell and buy the stock multiple times on the same day, ensuring you never hold more than one share of the stock. Find and return the maximum profit you can achieve. ...

January 1, 2026 · 5 min · David Nabergoj

LeetCode 189: Rotate Array

Happy new year! 🥳🎉🎉🎉 Let’s make 2026 awesome! Let’s solve LeetCode problem 189: Rotate Array. The instructions are as follows: Given an integer array nums, rotate the array to the right by \(k\) steps, where \(k\) is non-negative. Constraints: 1 <= nums.length <= 10^5 -2^31 <= nums[i] <= 2^31 - 1 0 <= k <= 10^5 This problem is fairly straightforward. I’ll present three solutions in C++. Let’s dive in! Note: rotations have a sort of cyclical property. If \(k\) is greater or equal to \(n\) (the length of nums), then rotating nums by with \(k\) is the same as rotating it with \(k\) modulo \(n\) – the remainder after dividing \(k\) by \(n\). We will always work with the remainder instead of the original \(k\). ...

December 31, 2025 · 4 min · David Nabergoj

FCPP 2: Successive wins

This is the solution for problem 2 from Fifty Challenging Problems in Probability by Frederick Mosteller (1987). The problem is paraphrased below; for reference, it is inspired by the original book. Ellis is a tennis player who has to compete against two players: his father and the tennis club champion. The champion is a better player than the father. Ellis will play a three-set series with alternating opponents. He can either play his father first, then the champion, then his father again; or the champion first, then his father, then the champion again. If he wins two sets in a row, he wins a special prize. ...

December 30, 2025 · 3 min · David Nabergoj

FCPP 1: The Sock Drawer

This is the first post in a series solving problems from Fifty Challenging Problems in Probability by Frederick Mosteller (1987). The problem is paraphrased below; for reference, it is inspired by the original book. A drawer contains some red and black socks. Two socks are drawn at random, and the probability that both are red is \(1/2\). What is the minimum total number of socks? What is the minimum if the number of black socks is even? Let’s dive in! ...

December 30, 2025 · 6 min · David Nabergoj