All Posts

Leetcode 1226: The Dining Philosophers

Five philosophers sit at a round table with bowls of spaghetti. Each philosopher alternates between thinking and eating. A philosopher can only eat when both their left and right forks are available. Design a system where no philosopher will starve and they can continue alternating between eating and thinking.

Leetcode 1227: Airplane Seat Assignment Probability

There are n passengers boarding an airplane with n seats. The first passenger has lost their ticket and picks a random seat. The remaining passengers sit in their assigned seat if available or pick a random seat if their assigned seat is taken. Return the probability that the nth person gets their own seat.

Leetcode 1233: Remove Sub-Folders from the Filesystem

You are given a list of folder paths, where each path represents a folder in the file system. The task is to remove all sub-folders from the list, keeping only the main folders.

Leetcode 1234: Replace the Substring for Balanced String

You are given a string containing only four kinds of characters: ‘Q’, ‘W’, ‘E’, and ‘R’. The string is balanced if each character appears exactly n/4 times, where n is the length of the string. The task is to find the minimum length of a substring that can be replaced to make the string balanced.

Leetcode 1237: Find Positive Integer Solution for a Given Equation

You are given a callable function f(x, y) with a hidden formula and a target value z. Your task is to find all pairs of positive integers x and y such that f(x, y) == z. The function is monotonically increasing, meaning: f(x, y) < f(x + 1, y) and f(x, y) < f(x, y + 1). Return a list of all such pairs. If no valid pairs are found, return an empty list.

Leetcode 1238: Circular Permutation in Binary Representation

Given two integers n and start, return a permutation of the integers from 0 to 2^n - 1 such that: p[0] = start, each pair of adjacent elements differ by exactly one bit in their binary representation, and p[0] and p[2^n - 1] also differ by exactly one bit.