☀️Sunny Coding💻

Welcome to Sunny Coding, the most positive coding blog on the internet! I love sharing what I learn about machine learning algorithms and frameworks, programming languages, and mathematics. I also post solutions for LeetCode problems that I solve. More about me here :)

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

FCPP 13: The Prisoner's Dillema

This is the solution to problem 13 from Fifty Challenging Problems in Probability by Frederick Mosteller (1987). The problem is paraphrased below; for reference, it is inspired by the original book. Prisoners \(A\), \(B\), and \(C\) with equally good records have applied for parole. Only two prisoners will be granted parole, but the prisoners themselves don’t know who. Prisoner \(A\) has a warder friend, who can answer this question. Instead of being direct, prisoner \(A\) contemplates asking: “Name one prisoner except me who will be granted parole.” He thinks that his chances of release before asking the question are \(\frac{2}{3}\). He incorrectly deduces that after asking, his chances go down to \(\frac{1}{2}\). ...

January 4, 2026 · 3 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

FCPP 9: Craps

This is the solution to problem 9 from Fifty Challenging Problems in Probability by Frederick Mosteller (1987). The problem is paraphrased below; for reference, it is inspired by the original book. In the gambling game of craps, we roll two fair six-sided dice and observe the total. If we roll a 7 or an 11, we win! We can also win in a more elaborate way: Throw anything except 2, 3, or 12. Our throw is called a point. Keep throwing. If we throw the point, we win! If we throw a 7, we lose. Otherwise, we just keep throwing. What is the probability of winning a game of craps? ...

January 3, 2026 · 4 min · David Nabergoj

FCPP 7: Curing the Compulsive Gambler

This is the solution to problem 7 from Fifty Challenging Problems in Probability by Frederick Mosteller (1987). The problem is paraphrased below; for reference, it is inspired by the original book. Mr. Brown is playing roulette. He always bets one dollar on 13. If the 38-number wheel lands on it, then he wins $35 and the stake back. His friend bets him $20 that he will be behind after 36 plays. ...

January 3, 2026 · 2 min · David Nabergoj