brain
tamnd's digital brain — notes, problems, research
43815 notes
We have several photo albums. Album i contains a[i] photos. We must build a cyclic gallery containing exactly n photos. Instead of choosing concrete photo IDs, we only need to output the album number for each position. The gallery is circular, so every position has two neighbors.
The problem gives us a single integer, area, which represents the area of a rectangle. Our task is to find two integers: - L, the length - W, the width such that: 1. L W == area 2. L = W 3.
The problem gives us an integer array nums, and we need to find every unique triplet of numbers whose sum is exactly 0. A triplet consists of three different indices: - i != j - i != k - j != k The values themselves may be equal, but the indices must be different.
The problem is a two-player turn-based game played on a row of stone piles. Each pile has a positive number of stones, and players take turns taking stones from the start of the remaining piles.
The problem asks us to design an autocomplete system that behaves similarly to a search engine suggestion feature. The system starts with a collection of historical sentences and the number of times each sentence has been typed before.
This problem asks us to locate the first occurrence of one string inside another string. The string we are searching for is called needle, and the larger string we search inside is called haystack.
We are given a collection of toy spiders. Each spider is a tree, represented by beads (nodes) connected with strings (edges). A spider with $k$ beads has $k-1$ strings connecting its beads so that all beads are connected and there are no cycles.
This problem gives us an array named cost, where each element represents the cost of stepping onto a particular stair. If cost[i] equals 10, that means stepping on stair i requires paying 10. From any stair, we are allowed to move either one step or two steps upward.
This is a long, structured technical guide with multiple substantial sections, worked examples, code, tables, and test c
This problem asks us to examine every possible subtree inside a binary tree and determine whether that subtree forms a valid Binary Search Tree, abbreviated as BST. Among all valid BST subtrees, we must return the maximum possible sum of node values.
We have an undirected graph where each vertex stores some positive integer, the number of mushrooms on that lawn. For every known edge, we are given two values: the gcd of the two endpoint values and the lcm of the two endpoint values.
The problem asks us to simulate the structure of a playoff tournament bracket. We are given n teams, numbered from 1 to n, where smaller numbers represent stronger teams.
We are asked to place a space rescue station in three-dimensional space such that the maximum distance from it to any of the given planets is minimized. Each planet is represented by its coordinates $(x, y, z)$.
The problem asks us to determine whether two binary expression trees are equivalent, where equivalence is defined as the trees representing the same arithmetic expression, modulo the order of addition since addition is commutative.
We need to validate whether a string follows the exact syntax of a Jabber ID.
This problem asks us to design an iterator that can traverse a deeply nested list structure as if it were a flat list of integers. The input is not a normal array.
We are given two integers, n and k. We look at all prime numbers from 2 up to n. Among those primes, we want to count how many can be written in the form:
The problem asks us to count the number of good meals that can be formed from a given list of food items. A good meal is defined as a pair of two different items whose combined deliciousness is a power of two.
The problem asks whether it is possible to transform a given integer array into a non-decreasing array by modifying at most one element. A non-decreasing array means that every element is less than or equal to the element that comes after it.
The problem asks us to rearrange an array so that it follows a strict alternating pattern: - nums[0] < nums[1] - nums[1] nums[2] - nums[2] < nums[3] - and so on. This pattern is called a wiggle sequence because the values repeatedly go up and down.
The problem asks us to find the length of the longest consecutive sequence path in a binary tree, where a consecutive sequence path is defined as a path in which the values increase by exactly one from parent to child.
The problem gives us three positive integers, a, b, and c. We are allowed to flip individual bits in either a or b. A flip means changing a bit from 0 to 1 or from 1 to 0. Our goal is to perform the minimum number of bit flips so that: The OR operation works bit by bit.
There are n boxes arranged in a straight line. Exactly one of them may contain the cereal flakes. The roommate leaves statements of two possible forms. If the hint says "To the left of i", then the flakes must be somewhere strictly before box i. Box i itself is also impossible.
That is a long-form technical guide with multiple required sections and detailed worked examples. I can provide the complete reference document, but it will be quite lengthy.
The problem requires us to transform an array nums of even length n into a complementary array. An array is complementar
This problem asks us to generate a specific path for Bob from the top-left corner (0, 0) to a destination (row, column)
The problem describes a scenario with a series of apple trees that grow apples for n consecutive days. Each day, the tree produces a number of apples given by apples[i], and these apples have a limited lifespan, given by days[i].
The problem asks us to partition a binary array arr into three non-empty contiguous segments such that each segment, when interpreted as a binary number (allowing leading zeros), is equal to the other two segments.
The problem asks us to transform a valid IPv4 address into its "defanged" version. A defanged IP address is created by replacing every period character "." with the string "[.]". An IPv4 address consists of four numeric segments separated by periods. For example, "1.1.1.
The problem asks us to find the length of the longest palindrome that can be constructed using the characters of a given string s. A palindrome is a string that reads the same forwards and backwards.
This problem asks us to merge user accounts based on shared email addresses. Each account is represented as a list of strings. The first string is the user's name, and every remaining string is an email address associated with that account.
The problem asks us to determine whether a binary tree is symmetric around its center. A tree is symmetric if the left subtree is a mirror reflection of the right subtree.
We have a parking segment represented by the interval [0, L]. Cars arrive one at a time, always driving from left to right, and each driver wants to park at the earliest possible position.
The problem asks us to compute the number of ways to completely tile a 2 x n board using two types of tiles: a domino (2 x 1) and a tromino shape.
This problem asks us to find the maximum sum of any two distinct numbers in an integer array nums such that their sum is strictly less than a given integer k.
The problem asks us to group together all strings that are anagrams of each other. Two strings are considered anagrams if they contain exactly the same characters with the same frequencies, but possibly in a different order.
The problem gives us an integer array nums and asks us to find the index of any peak element. A peak element is defined as an element that is strictly greater than its immediate neighbors.
The problem asks us to construct the longest possible string using only the characters 'a', 'b', and 'c', while satisfyi
This problem asks us to repeatedly apply character shifts to a string of lowercase English letters. We are given two inputs: - A string s, consisting only of lowercase English letters.
This problem asks us to create a deep copy of an N-ary tree. An N-ary tree is a tree where each node can have zero or mo
This problem asks us to find, for each interval in a list, the "right interval" that starts at or after the end of the current interval and is the closest such interval in terms of starting time.
This problem asks us to generate a monthly financial summary for each country using information from two database tables: Transactions and Chargebacks. The Transactions table stores incoming transactions.
We are given a sequence of integers and need to compute their total sum. The input starts with an integer n, which tells us how many numbers follow. Each of the next n lines contains one element of the array. The task is simply to add all of them together and print the result.
We need to build a permutation of numbers from 1 to n. Position j contains volume p(j). A positive integer i is called a divisor of the disposition if there exists some position j such that both j and p(j) are divisible by i.
The problem gives us two axis-aligned rectangles, meaning their sides are parallel to the X-axis and Y-axis. Each rectangle is represented as: Where: - (x1, y1) is the bottom-left corner - (x2, y2) is the top-right corner The task is to determine whether these two rectangles…
We are asked to compute the factorial of a given integer $n$. Factorial is the product of all positive integers up to $n$, so for $n = 3$, the factorial is $1 times 2 times 3 = 6$. The input is a single integer, and the output is the single integer result of this product.
We are given a small array of integers and need to find the smallest value that is strictly larger than the minimum element in the array.
We are given a decimal integer as a string. The number can be extremely large, up to 100 digits long, so it may not fit into normal integer types in many programming languages. The task is to determine the smallest Java integer type that can store this value.
This problem asks us to remove the nth node counted from the end of a singly linked list and return the modified list. A singly linked list is a sequence of nodes where each node contains a value and a pointer to the next node.
The problem is asking us to design a specialized queue that allows insertions and removals not only at the front and bac
The problem asks us to generate every unique palindrome that can be formed by rearranging the characters of a given string. A palindrome is a string that reads the same forward and backward. For example, "abba" and "racecar" are palindromes.
The problem asks us to construct the shortest possible string that contains both str1 and str2 as subsequences. A subsequence does not require characters to appear contiguously. Instead, the characters only need to appear in the same relative order.
The Death Star is a sphere of radius R. Its center starts at point A and moves forever in a straight line with constant velocity vector v. Every mine consists of two kinds of geometry. The first part is a sphere centered at O with radius r. The second part is a set of spikes.
The problem gives us a string s that represents several positive integers concatenated together without spaces. Original
This problem models a computer network as an undirected graph. Each computer is a node, and each ethernet cable is an ed
The problem presents a lock with four wheels, each wheel labeled from '0' to '9', which can rotate forwards or backwards. The lock starts at '0000', and we are given a list of "deadends," which are lock states that will cause the lock to freeze if reached.
This problem describes a frog moving through an undirected tree. A tree is a connected graph with no cycles, which means
The problem describes a binary watch that uses LEDs to represent time. The watch has two sections. The top section contains 4 LEDs for the hour, and the bottom section contains 6 LEDs for the minutes. Each LED represents a binary digit.
The problem requires computing the result of a mathematical expression containing fractions with addition and subtraction operators. The input is a single string, expression, which consists of positive or negative fractions in the format numerator/denominator.
This problem asks us to determine whether a given string is a palindrome after applying two transformations: 1. Convert all uppercase letters to lowercase. 2. Remove all non-alphanumeric characters. An alphanumeric character is any English letter (a-z, A-Z) or digit (0-9).
This problem asks us to analyze a database table named Submissions and determine how many unique comments belong to each post.
This problem asks us to process a stream of non-negative integers and continuously maintain a compact representation of all numbers seen so far. Instead of storing every individual number separately, we want to group consecutive numbers into disjoint intervals.
We are given a subway system of n stations connected by exactly n passages, each passage connecting two distinct stations. The system forms a connected graph where each station can reach every other station.
The problem gives us n identical unit cubes that must be placed inside a cubic room. The goal is to minimize how many boxes directly touch the floor. The placement rule is the important part of the problem.
The problem gives us two arrays: - rowSum, where rowSum[i] represents the total sum required for row i - colSum, where c
The problem asks us to take a string s and an integer array indices of the same length, and produce a new string where e
The test contains several questions that must be answered in order. Each question has multiple answer choices, and exactly one of them is correct. Vaganych does not know any correct answers in advance, but after making a mistake he remembers which options were wrong.
We are given a tree of n cities, meaning each city is connected in such a way that there is exactly one simple path between any two cities. Roads are undirected, and each road has a length of 1.
This problem asks us to reverse only a specific portion of a singly linked list, rather than reversing the entire list. We are given the head of a linked list and two integer positions, left and right, where left <= right.
We are asked to count the number of distinct binary search trees (BSTs) that have exactly n nodes labeled from 1 to n, with the additional constraint that the height of each tree is at least h.
The cylinder has n slots arranged in a circle, and exactly k of them contain bullets. Before the game starts, the cylinder is rotated uniformly at random, so every cyclic shift is equally likely. After the rotation, Sasha shoots first.
This problem asks us to simulate a dynamic permutation of integers and answer position queries as elements continuously
This problem asks us to find the lowest common ancestor, abbreviated as LCA, of all the deepest leaf nodes in a binary tree. A leaf node is any node with no children. The depth of the root is 0, and every level downward increases the depth by 1.
This problem asks us to generate all unique combinations of exactly k distinct numbers chosen from the range 1 to 9 such that their sum equals n. Each number can only be used once in a combination. This means combinations like [1,1,5] are invalid because the number 1 is repeated.
This problem asks us to determine whether three given points in a 2D Cartesian plane form a valid boomerang. A boomerang is defined as a set of three points that are all distinct and not in a straight line. In other words, the points must not coincide and must not be collinear.
We are given the sequence of goals scored during a football match. Every line after the first contains the name of the team that scored one goal. The task is to determine which team scored more goals overall.
The problem asks us to reorder an array of integers based on the frequency of each value. Specifically, elements with lo
The problem defines a special kind of binary tree called a Fibonacci tree. The structure is recursive: - order(0) is an empty tree. - order(1) is a single node. - order(n) has: - a root node, - a left subtree equal to order(n - 2), - a right subtree equal to order(n - 1).
The snitch moves along a fixed polyline in 3D space. It starts at the first vertex and travels segment by segment at constant speed vs. Harry starts at another point and can move in any direction at constant speed vp, where vp = vs.
The problem asks us to transform a Binary Search Tree, abbreviated as BST, into a sorted circular doubly linked list. The transformation must happen in place, meaning we are not allowed to create entirely new nodes for the linked list.
This problem asks us to find the in-order successor of a given node inside a Binary Search Tree, abbreviated as BST. Unlike the classic version of the problem, we are not given access to the root of the tree.
The problem asks us to generate every possible full binary tree that contains exactly n nodes. A full binary tree is a special kind of binary tree where every node has either exactly two children or no children at all. In other words, a node can never have only one child.
The problem gives an integer array nums and allows only one type of operation, decreasing any element by 1. We may perform this operation as many times as needed on any elements. Our goal is to transform the array into a zigzag array with the minimum number of moves.
The problem gives us all adjacent pairs from an unknown array nums, and our task is to reconstruct the original array. Suppose the original array was: The adjacent pairs would be: The important detail is that the pairs can appear in any order and can also be reversed.
This problem asks us to analyze a collection of user activity logs and determine how many users have a specific number of unique active minutes.
We are given the dimensions of an uploaded photo, height h and width w. We want to cut out a smaller rectangle from it. The cut rectangle must satisfy three conditions.
Each tooth belongs to exactly one row. When Valerie eats one crucian using a row, every tooth in that row loses one unit of viability. A row becomes unusable as soon as at least one tooth inside it would drop below zero.
This problem gives us a special type of linked list called an immutable linked list. Unlike a normal linked list problem
This problem asks us to design a small tracking system for an underground railway network. The system must support three
The problem asks us to find the smallest positive integer x such that the product of all of its digits equals the given integer num.
We are given a table representing the economy of Berland over n days and m months. Each cell in the table contains either 1 or -1, indicating a profit or a loss for that day of that month.
The problem describes a set of cars driving toward the same destination, represented by the integer target. Each car starts at a unique position and moves at a constant speed. Cars cannot overtake each other.
This problem asks us to determine whether a circular array contains a valid cycle under a specific movement rule. Each element in the array represents how far we move from the current index.
We are asked to place as many standard dominoes as possible on a rectangular board of size _M_ by _N_. Each domino covers exactly two adjacent squares, and dominoes cannot overlap or extend outside the board.
We are given a set of N random integers, where each integer i can take any value in a given inclusive range [L_i, R_i], all values equally likely. The task is to compute the probability that at least K% of these N integers start with the digit 1.
The problem asks us to simulate a painter working on an 8×8 chessboard. Every square starts white, and the painter can perform only two operations: paint an entire row black or paint an entire column black. Painting the same square multiple times has no effect beyond the first.
This problem asks us to classify nodes in a binary tree based on their role in the tree structure. The input is represen
The problem is asking us to find the shorthand RGB color that is most similar to a given full-length RGB color string.
We are given an array of at most 100 integers. Every value lies between 1 and 60. The task is simply to print the array in non-decreasing order.
We are asked to compute the average sum of digits of a number _A_ when it is expressed in all bases from 2 up to _A_ - 1. The input is a single integer _A_ between 3 and 1000.