brain

tamnd's digital brain — notes, problems, research

42715 notes

LeetCode 838 - Push Dominoes

This problem models a chain reaction of falling dominoes. We are given a string where each character represents the initial state of a domino in a row. A domino can be in one of three states: - 'L' means the domino has been pushed to the left.

leetcodemediumtwo-pointersstringdynamic-programming
CF 16E - Fish

We have n fish in a lake. Every day, exactly one unordered pair of currently alive fish is chosen uniformly at random. When fish i meets fish j, fish i eats fish j with probability a[i][j], and fish j eats fish i with probability a[j][i] = 1 - a[i][j].

codeforcescompetitive-programmingbitmasksdpprobabilities
CF 86B - Tetris revisited

We have a rectangular board where some cells are already blocked by and the remaining cells . must be covered by polyominoes. The allowed pieces are extremely flexible: any connected shape consisting of 2, 3, 4, or 5 cells may be used, with arbitrary rotations and reflections.

codeforcescompetitive-programmingconstructive-algorithmsgraph-matchingsgreedymath
LeetCode 1592 - Rearrange Spaces Between Words

The problem requires rearranging spaces in a given string text so that all words are separated by the maximum possible e

leetcodeeasystring
LeetCode 1637 - Widest Vertical Area Between Two Points Containing No Points

This problem gives us a list of points on a 2D plane, where each point is represented as [x, y]. We need to find the widest vertical area that contains no points strictly inside it. A vertical area is defined by two vertical lines.

leetcodeeasyarraysorting
LeetCode 72 - Edit Distance

The problem asks us to compute the minimum number of edit operations needed to transform one string into another. The allowed operations are insertion, deletion, and replacement of a single character. Each operation has a cost of exactly one.

leetcodemediumstringdynamic-programming
LeetCode 1093 - Statistics from a Large Sample

This problem asks us to compute several descriptive statistics-minimum, maximum, mean, median, and mode-from a very large sample of integers ranging from 0 to 255.

leetcodemediumarraymathprobability-and-statistics
LeetCode 200 - Number of Islands

The problem gives us a two dimensional grid where each cell contains either '1' or '0'. A cell containing '1' represents land, while a cell containing '0' represents water. An island is defined as a group of connected land cells.

leetcodemediumarraydepth-first-searchbreadth-first-searchunion-findmatrix
CF 93A - Frames

The folders are displayed in a grid with exactly m columns per row. Folder 1 is in the top-left corner, folder 2 is next to it, and so on. After every m folders we move to the next row. A rectangular frame selection toggles every folder inside the rectangle.

codeforcescompetitive-programmingimplementation
LeetCode 1050 - Actors and Directors Who Cooperated At Least Three Times

This problem asks us to identify every (actorid, directorid) pair where an actor and a director have collaborated at least three times. The input is a database table named ActorDirector. Each row represents one collaboration event between an actor and a director.

leetcodeeasydatabase
LeetCode 1450 - Number of Students Doing Homework at a Given Time

This problem asks us to determine how many students are doing homework at a specific point in time, given arrays represe

leetcodeeasyarray
CF 77C - Beavermuncher-0xFF

We have a tree where each vertex initially contains some number of beavers. The robot starts at a fixed vertex s. Every time it traverses an edge from u to v, it immediately eats exactly one beaver at v. If v already has zero beavers left, the move is impossible.

codeforcescompetitive-programmingdfs-and-similardpdsugreedytrees
LeetCode 1045 - Customers Who Bought All Products

This problem asks us to identify all customers who have purchased every product listed in the Product table. In other words, a customer is eligible for the output if, for each productkey in the Product table, there exists a corresponding row in the Customer table where that…

leetcodemediumdatabase
CF 70C - Lucky Tickets

Each ticket is described by two positive integers. The first is the series number a, the second is the ticket number inside that series b.

codeforcescompetitive-programmingbinary-searchdata-structuressortingstwo-pointers
CF 38C - Blinds

We have a set of horizontal blind stripes of varying lengths, and our goal is to construct a rectangular blind for a window using these stripes. Each stripe can be cut into smaller pieces, but pieces cannot be shorter than a given minimum length, l.

codeforcescompetitive-programmingbrute-force
CF 123E - Maze

We are given a tree, and two independent probability distributions over its vertices. One distribution chooses the starting vertex of a DFS, the other chooses the target vertex where the search stops.

codeforcescompetitive-programmingdfs-and-similardpprobabilitiestrees
LeetCode 342 - Power of Four

This problem asks us to determine whether a given integer n is an exact power of four. In other words, we need to check whether there exists some integer x such that: Examples of powers of four are: The input consists of a single integer n, and the expected output is a boolean…

leetcodeeasymathbit-manipulationrecursion
LeetCode 403 - Frog Jump

The problem describes a frog trying to cross a river by jumping across stones placed at specific positions. The input array stones contains the positions of all stones in sorted ascending order. The frog starts on the first stone, which is always at position 0.

leetcodehardarraydynamic-programming
Project Euler Problem 935

A square of side length b<1 is rolling around the inside of a larger square of side length 1, always touching the larger

eulermathematicscompetitive-programming
Project Euler Problem 920

For a positive integer n we define tau(n) to be the count of the divisors of n.

eulermathematicscompetitive-programming
LeetCode 81 - Search in Rotated Sorted Array II

This problem asks us to determine whether a target value exists inside a rotated sorted array that may contain duplicate values. The original array was sorted in non-decreasing order, meaning values are arranged from smallest to largest, and duplicates are allowed.

leetcodemediumarraybinary-search
LeetCode 208 - Implement Trie (Prefix Tree)

The problem asks us to design and implement a Trie, also called a Prefix Tree. A Trie is a specialized tree structure for storing strings in a way that makes prefix-based operations very efficient.

leetcodemediumhash-tablestringdesigntrie
Project Euler Problem 927

A full k-ary tree is a tree with a single root node, such that every node is either a leaf or has exactly k ordered chil

eulermathematicscompetitive-programming
Project Euler Problem 3

The prime factors of 13195 are 5, 7, 13 and 29.

eulermathematicscompetitive-programming
Project Euler Problem 899

Two players play a game with two piles of stones.

eulermathematicscompetitive-programming
LeetCode 204 - Count Primes

The problem asks us to count how many prime numbers exist that are strictly smaller than a given integer n. A prime number is a positive integer greater than 1 that has exactly two divisors: 1 and itself. Examples of prime numbers include 2, 3, 5, 7, and 11.

leetcodemediumarraymathenumerationnumber-theory
Project Euler Problem 988

Solution to Project Euler Problem 988.

eulermathematicscompetitive-programming
Project Euler Problem 903

A permutation pi of 1, dots, n can be represented in one-line notation as pi(1),ldots,pi(n) .

eulermathematicscompetitive-programming
Project Euler Problem 936

A peerless tree is a tree with no edge between two vertices of the same degree.

eulermathematicscompetitive-programming
Project Euler Problem 934

We define the unlucky prime of a number n, denoted u(n), as the smallest prime number p such that the remainder of n div

eulermathematicscompetitive-programming
Project Euler Problem 938

A deck of cards contains R red cards and B black cards.

eulermathematicscompetitive-programming
Project Euler Problem 639

A multiplicative function f(x) is a function over positive integers satisfying f(1)=1 and f(a b)=f(a) f(b) for any two c

eulermathematicscompetitive-programming
Project Euler Problem 966

nLet I(a, b, c) be the largest possible area of intersection between a triangle of side lengths a, b, c and a circle whi

eulermathematicscompetitive-programming
Project Euler Problem 995

For each prime p and each positive integer n define two polynomials: Let S(p) be the smallest positive integer s such th

eulermathematicscompetitive-programming
Project Euler Problem 961

nThis game starts with a positive integer.

eulermathematicscompetitive-programming
Project Euler Problem 7

By listing the first six prime numbers: 2, 3, 5, 7, 11, and 13, we can see that the 6th prime is 13.

eulermathematicscompetitive-programming
LeetCode 7 - Reverse Integer

The problem asks us to reverse the digits of a signed 32-bit integer. Given an integer x, we must return a new integer whose digits appear in reverse order while preserving the sign. For example, if the input is 123, reversing the digits produces 321.

leetcodemediummath
CF 1941A - Rudolf and the Ticket

The problem gives us two arrays of coin values. The first array represents coins in Rudolf's left pocket, and the second array represents coins in his right pocket.

codeforcescompetitive-programmingbrute-forcemath
Project Euler Problem 9

A Pythagorean triplet is a set of three natural numbers, a lt b lt c, for which, For example, 3^2 + 4^2 = 9 + 16 = 25 =

eulermathematicscompetitive-programming
Project Euler Problem 937

Let theta=sqrt{-2}. Define T to be the set of numbers of the form a+btheta, where a and b are integers and either agt 0,

eulermathematicscompetitive-programming
LeetCode 190 - Reverse Bits

The problem asks us to reverse the binary representation of a 32-bit integer. Instead of reversing the decimal digits of a number, we reverse the order of its individual bits.

leetcodeeasydivide-and-conquerbit-manipulation
Project Euler Problem 957

There is a plane on which all points are initially white, except three red points and two blue points.

eulermathematicscompetitive-programming
Project Euler Problem 962

Given is an integer sided triangle ABC with BC le AC le AB.nk is the angular bisector of angle ACB.nm is the tangent at

eulermathematicscompetitive-programming
Project Euler Problem 375

Let Sn be an integer sequence produced with the following pseudo-random number generator: Let A(i, j) be the minimum of

eulermathematicscompetitive-programming
Project Euler Problem 369

In a standard 52 card deck of playing cards, a set of 4 cards is a Badugi if it contains 4 cards with no pairs and no tw

eulermathematicscompetitive-programming
LeetCode 205 - Isomorphic Strings

The problem asks us to determine whether two strings, s and t, are isomorphic. Two strings are considered isomorphic if there exists a one-to-one mapping between characters in s and characters in t such that replacing every character in s according to this mapping produces t.

leetcodeeasyhash-tablestring
LeetCode 201 - Bitwise AND of Numbers Range

The problem asks us to compute the bitwise AND of every integer in the inclusive range [left, right]. For example, if left = 5 and right = 7, the numbers in the range are: Applying bitwise AND across all values: So the answer is 4.

leetcodemediumbit-manipulation
Project Euler Problem 296

Given is an integer sided triangle ABC with BC le AC le AB.

eulermathematicscompetitive-programming
Project Euler Problem 939

Two players A and B are playing a variant of Nim.

eulermathematicscompetitive-programming
Project Euler Problem 997

There are xyz dice arranged in an x times y times z box such that touching faces have the same value.

eulermathematicscompetitive-programming
Project Euler Problem 908

A clock sequence is a periodic sequence of positive integers that can be broken into contiguous segments such that the s

eulermathematicscompetitive-programming
LeetCode 202 - Happy Number

This problem asks us to determine whether a given positive integer n is a happy number. A happy number is defined through a repeated transformation process. Starting with the original number, we repeatedly replace it with the sum of the squares of its digits.

leetcodeeasyhash-tablemathtwo-pointers
Project Euler Problem 887

Consider the problem of determining a secret number from a set 1, ..., N by repeatedly choosing a number y and asking "I

eulermathematicscompetitive-programming
Project Euler Problem 983

Solution to Project Euler Problem 983.

eulermathematicscompetitive-programming
Project Euler Problem 576

A bouncing point moves counterclockwise along a circle with circumference 1 with jumps of constant length l lt 1, until

eulermathematicscompetitive-programming
CF 4B - Before an Exam

We are given d days and a target total number of study hours, sumTime. For every day, Peter must study at least minTime[i] hours and at most maxTime[i] hours. The task is to construct any valid schedule whose total sum is exactly sumTime.

codeforcescompetitive-programmingconstructive-algorithmsgreedy
LeetCode 196 - Delete Duplicate Emails

This problem provides a database table named Person with two columns: The id column is unique because it is the primary key. The email column may contain duplicate values, meaning multiple rows can share the same email address.

leetcodeeasydatabase
Project Euler Problem 979

Solution to Project Euler Problem 979.

eulermathematicscompetitive-programming
Project Euler Problem 726

Consider a stack of bottles of wine.

eulermathematicscompetitive-programming
Project Euler Problem 968

nDefinennas the sum of 2^a3^b5^c7^d11^e over all quintuples of non-negative integers (a, b, c, d, e) such that the sum o

eulermathematicscompetitive-programming
Project Euler Problem 784

Let's call a pair of positive integers p, q (p lt q) reciprocal, if there is a positive integer rlt p such that r equals

eulermathematicscompetitive-programming
Project Euler Problem 987

Solution to Project Euler Problem 987.

eulermathematicscompetitive-programming
Project Euler Problem 911

An irrational number x can be uniquely expressed as a continued fraction [a0; a1,a2,a3,dots]: where a0 is an integer and

eulermathematicscompetitive-programming
Project Euler Problem 984

Solution to Project Euler Problem 984.

eulermathematicscompetitive-programming
Project Euler Problem 969

nStarting at zero, a kangaroo hops along the real number line in the positive direction.

eulermathematicscompetitive-programming
Project Euler Problem 910

An L-expression is defined as any one of the following: - a natural number; - the symbol A; - the symbol Z; - the symbol

eulermathematicscompetitive-programming
Project Euler Problem 973

Solution to Project Euler Problem 973.

eulermathematicscompetitive-programming
Project Euler Problem 534

The classical eight queens puzzle is the well known problem of placing eight chess queens on an 8 times 8 chessboard so

eulermathematicscompetitive-programming
Project Euler Problem 978

Solution to Project Euler Problem 978.

eulermathematicscompetitive-programming
Project Euler Problem 976

Solution to Project Euler Problem 976.

eulermathematicscompetitive-programming
Project Euler Problem 777

For coprime positive integers a and b, let C{a,b} be the curve defined by: where t varies between 0 and 2pi.

eulermathematicscompetitive-programming
Project Euler Problem 980

Solution to Project Euler Problem 980.

eulermathematicscompetitive-programming
Project Euler Problem 977

Solution to Project Euler Problem 977.

eulermathematicscompetitive-programming
Project Euler Problem 925

Let B(n) be the smallest number larger than n that can be formed by rearranging digits of n, or 0 if no such number exis

eulermathematicscompetitive-programming
Project Euler Problem 991

Solution to Project Euler Problem 991.

eulermathematicscompetitive-programming
Project Euler Problem 975

Solution to Project Euler Problem 975.

eulermathematicscompetitive-programming
Project Euler Problem 923

A Young diagram is a finite collection of (equally-sized) squares in a grid-like arrangement of rows and columns, such t

eulermathematicscompetitive-programming
Project Euler Problem 897

Let G(n) denote the largest possible area of an n-gona polygon with n sides contained in the region (x, y) in Bbb R^2: x

eulermathematicscompetitive-programming
Project Euler Problem 960

nThere are n distinct piles of stones, each of size n-1.

eulermathematicscompetitive-programming
Project Euler Problem 260

A game is played with three piles of stones and two players.

eulermathematicscompetitive-programming
Project Euler Problem 929

A composition of n is a sequence of positive integers which sum to n.

eulermathematicscompetitive-programming
Project Euler Problem 924

Let B(n) be the smallest number larger than n that can be formed by rearranging digits of n, or 0 if no such number exis

eulermathematicscompetitive-programming
CF 1941B - Rudolf and 121

We are given an array of non-negative integers. In one operation, we choose an index $i$ such that $2 le i le n-1$, and

codeforcescompetitive-programmingbrute-forcedpgreedymath
Project Euler Problem 8

The four adjacent digits in the 1000-digit number that have the greatest product are 9 times 9 times 8 times 9 = 5832.

eulermathematicscompetitive-programming
Project Euler Problem 996

Solution to Project Euler Problem 996.

eulermathematicscompetitive-programming
LeetCode 203 - Remove Linked List Elements

The problem asks us to remove every node from a singly linked list whose value is equal to a given integer val. After all matching nodes are removed, we must return the head of the modified linked list.

leetcodeeasylinked-listrecursion
Project Euler Problem 891

A round clock only has three hands: hour, minute, second.

eulermathematicscompetitive-programming
LeetCode 3 - Longest Substring Without Repeating Characters

The problem gives a string s and asks for the length of the longest substring that contains no repeated characters. A substring is a continuous section of the string. This detail matters because characters must remain adjacent.

leetcodemediumhash-tablestringsliding-window
Project Euler Problem 521

Let operatorname{smpf}(n) be the smallest prime factor of n.

eulermathematicscompetitive-programming
Project Euler Problem 963

NOTE: This problem is related to Problem 882.

eulermathematicscompetitive-programming
Project Euler Problem 256

Tatami are rectangular mats, used to completely cover the floor of a room, without overlap.

eulermathematicscompetitive-programming
LeetCode 199 - Binary Tree Right Side View

The problem gives us the root node of a binary tree and asks us to determine which nodes are visible when looking at the tree from the right side.

leetcodemediumtreedepth-first-searchbreadth-first-searchbinary-tree
Project Euler Problem 994

Solution to Project Euler Problem 994.

eulermathematicscompetitive-programming
Project Euler Problem 958

The Euclidean algorithm can be used to find the greatest common divisor of two positive integers.

eulermathematicscompetitive-programming
LeetCode 5 - Longest Palindromic Substring

The problem asks us to find the longest substring of a given string that is also a palindrome. A palindrome is a sequence that reads the same forward and backward. The substring must be contiguous, which means the characters must appear next to each other in the original string.

leetcodemediumtwo-pointersstringdynamic-programming
Project Euler Problem 902

A permutation pi of 1, dots, n can be represented in one-line notation as pi(1),ldots,pi(n) .

eulermathematicscompetitive-programming
Project Euler Problem 565

Let sigma(n) be the sum of the divisors of n.

eulermathematicscompetitive-programming
Project Euler Problem 912

Let sn be the n-th positive integer that does not contain three consecutive ones in its binary representation.

eulermathematicscompetitive-programming
LeetCode 11 - Container With Most Water

The problem gives an array called height, where each element represents the height of a vertical line drawn on a coordinate plane. The line at index i starts at (i, 0) and ends at (i, height[i]).

leetcodemediumarraytwo-pointersgreedy
CF 1941C - Rudolf and the Ugly String

We are given a string and want to remove the minimum number of characters so that the resulting string no longer contains "pie" or "map" as a substring.

codeforcescompetitive-programmingdpgreedystrings