brain
tamnd's digital brain — notes, problems, research
43815 notes
This problem asks us to select as many non-overlapping substrings as possible from a given lowercase string s, while sat
We are asked to count all pairs of clients whose assigned numbers are exact opposites. Each client has a number between -10 and 10, and a pair is valid if one client has number $x$ and the other has number $-x$.
We have a rectangular cornfield represented as a grid of size n × m, where each cell contains a certain number of tons of corn. The father wants to divide this field among three sons in such a way that each son receives exactly a predetermined amount of corn: A, B, or C tons.
The problem gives us a circular array nums, and for every element, we must find the next greater element. The phrase next greater element means the first value encountered while moving forward in the array that is strictly larger than the current number.
We are given an arithmetic expression built from terms involving a single variable a. Every term is one of two forms:
The problem asks us to perform a level order traversal on a binary tree. A binary tree is a hierarchical structure where each node can have at most two children, commonly referred to as the left child and the right child.
The problem asks us to reconstruct a binary matrix with exactly two rows and n columns given three constraints: the sum
The problem gives us an integer array nums and a target integer target. We must select exactly three elements from the array, using distinct indices, and compute their sum. Among all possible three-number sums, we want the one whose value is closest to the target.
We are asked to maximize the amount of money Vasya can have at the end of _n_ days if he starts with a given sum of bourles and can buy and later sell Martian dollars.
The problem asks us to maximize the total points we can collect from a row of cards, where each card has a point value.
We are asked to count all distinct real roots of quadratic equations of the form , where ranges from 1 to and ranges from 1 to . Each pair defines one quadratic. The output is the total number of distinct real roots across all these quadratics.
This problem asks us to determine how many different valid ways a numeric string can be decoded into letters using the mapping: - "1" → 'A' - "2" → 'B' - ... - "26" → 'Z' The input is a string s containing only digits.
LeetCode 1349 is long and detailed enough that a complete high quality guide with all required sections, full prose expl
This problem asks us to determine the maximum frequency of an element in an integer array nums after performing at most k increment operations. Each operation allows you to choose an element and increase it by 1.
The problem asks us to compute the number of ways to distribute n distinct candies into k bags such that every bag has a
We are given a single lowercase string. Somewhere inside this string, there exists a hidden palindrome of odd length, but the palindrome was split into three consecutive parts:
The problem gives us a special type of doubly linked list where every node contains four fields: The next and prev pointers behave exactly like a normal doubly linked list. The extra child pointer introduces another linked list that branches downward from the current node.
This problem asks us to construct a mathematical expression using only the number x repeatedly, combined with the operators +, -, , and /, such that the final expression evaluates exactly to target.
Let '' denote the bitwise AND operation.
A driller drills for water.
A frog is placed on the number line.
The problem asks us to count how many bits are set to 1 in the binary representation of a positive integer n. A set bit is simply a bit whose value is 1. For example, the number 11 in binary is: This binary representation contains three 1 bits, so the answer is 3.
Solution to Project Euler Problem 979.
nThere are n distinct piles of stones, each of size n-1.
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
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
The function s(n) is defined recursively for positive integers by s(1) = 1 and s(n+1) = big(s(n) - 1big)^3 +2 for ngeq 1
Solution to Project Euler Problem 973.
For every integer n 1, the family of functions f{n,a,b} is defined by for integers a, b, x with 0 < a < n, 0 le b < n, 0
A contiguous range of positive integers is called a divisible range if all the integers in the range can be arranged in
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.
Let Sn be an integer sequence produced with the following pseudo-random number generator: Let A(i, j) be the minimum of
Given any integer n gt 1 a binary factor tree T(n) is defined to be: - A tree with the single node n when n is prime.
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.
The numbers from 1 to 12 can be arranged into a 3 times 4 matrix in either row-major or column-major order: By swapping
Three epistemologists, known as A, B, and C, are in a room, each wearing a hat with a number on it.
Let p be a prime of the form 5k-4 and define fp(x) = left(x^k+xright) bmod p.nnLet C(p) be the number of values 0 le x l
Tatami are rectangular mats, used to completely cover the floor of a room, without overlap.
Solution to Project Euler Problem 975.
This problem is based on (but not identical to) the scoring for the card game Cribbage.
By listing the first six prime numbers: 2, 3, 5, 7, 11, and 13, we can see that the 6th prime is 13.
Let sigma(n) be the sum of the divisors of n.
An integer partition of a number n is a way of writing n as a sum of positive integers.
A Young diagram is a finite collection of (equally-sized) squares in a grid-like arrangement of rows and columns, such t
Solution to Project Euler Problem 977.
The problem gives two individually sorted integer arrays, nums1 and nums2, with lengths m and n. The task is to compute the median of the combined sorted sequence formed by merging both arrays. The median is the middle value of a sorted sequence.
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.
Bozo sort, not to be confused with the slightly less efficient bogo sort, consists out of checking if the input sequence
For a positive integer n we define tau(n) to be the count of the divisors of n.
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
For each prime p and each positive integer n define two polynomials: Let S(p) be the smallest positive integer s such th
A permutation pi of 1, dots, n can be represented in one-line notation as pi(1),ldots,pi(n) .
Claire Voyant is a teacher playing a game with a class of students.
The Fibonacci sequence (fi) is the unique sequence such that - f0=0 - f1=1 - f{i+1}=fi+f{i-1} Similarly, there is a uniq
The sequence sn is defined by s1 = 102022661 and sn = s{n-1}^2 bmod {998388889} for n 1.
Solution to Project Euler Problem 982.
Consider the problem of determining a secret number from a set 1, ..., N by repeatedly choosing a number y and asking "I
The problem describes a row of houses, where each house contains some amount of money. You are acting as a robber who wants to maximize the total amount stolen, but there is one important restriction, you cannot rob two adjacent houses.
A permutation pi of 1, dots, n can be represented in one-line notation as pi(1),ldots,pi(n) .
A round number is a number that ends with one or more zeros in a given base.
The sum of the primes below 10 is 2 + 3 + 5 + 7 = 17.
A Young diagram is a finite collection of (equally-sized) squares in a grid-like arrangement of rows and columns, such t
An infant's toy consists of n cups, labelled C1,dots,Cn in increasing order of size.
The sequence an is defined by a1=1, and then recursively for ngeq1: The first ten terms are 1, 2, -5, 4, 17, -10, -17, 8
The prime factors of 13195 are 5, 7, 13 and 29.
An ascent of a column j in a matrix occurs if the value of column j is smaller than the value of column j + 1 in all row
Solution to Project Euler Problem 978.
Let {x} denote the fractional part of a real number x.nnDefine fN(x) to be the minimal value of {nx} for integer n satis
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
Solution to Project Euler Problem 987.
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]).
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
Solution to Project Euler Problem 983.
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.
Solution to Project Euler Problem 981.
The four adjacent digits in the 1000-digit number that have the greatest product are 9 times 9 times 8 times 9 = 5832.
An L-expression is defined as any one of the following: - a natural number; - the symbol A; - the symbol Z; - the symbol
The following game is a classic example of Combinatorial Game Theory: Two players start with a strip of n white squares
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.
The problem asks us to reverse a singly linked list. A singly linked list is a sequence of nodes where each node stores a value and a pointer to the next node in the sequence. The input, head, represents the first node of the linked list.
There are xyz dice arranged in an x times y times z box such that touching faces have the same value.
Solution to Project Euler Problem 985.
The problem gives us a database table named Weather that stores daily temperature records. Each row contains three fields: a unique id, a recordDate, and the temperature recorded on that date.
Solution to Project Euler Problem 993.
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.
Given a right-angled triangle with integer sides, the smaller angle formed by the two medians drawn on the the two perpe
The sum of the squares of the first ten natural numbers is, The square of the sum of the first ten natural numbers is, H
Solution to Project Euler Problem 991.
nThis game starts with a positive integer.
nStarting at zero, a kangaroo hops along the real number line in the positive direction.
The Euclidean algorithm can be used to find the greatest common divisor of two positive integers.
Two players A and B are playing a variant of Nim.
An irrational number x can be uniquely expressed as a continued fraction [a0; a1,a2,a3,dots]: where a0 is an integer and
For coprime positive integers a and b, let C{a,b} be the curve defined by: where t varies between 0 and 2pi.
Write Fn for the n-th Fibonacci number, with F1 = F2 = 1 and F{n+1} = Fn + F{n-1}.
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.
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.
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.
The problem gives us two non empty singly linked lists. Each linked list represents a non negative integer, but the digits are stored in reverse order. That means the head node contains the least significant digit.
Solution to Project Euler Problem 992.