brain
tamnd's digital brain — notes, problems, research
42715 notes
The problem asks us to design a data structure that simulates a royal inheritance system. There is a king at the top of the family tree, and over time people can be born or die. We must support three operations efficiently: 1. Add a child to an existing person. 2.
The problem asks us to count how many non-empty contiguous subarrays have a sum that is divisible by a given integer k. A subarray is any continuous segment of the array. For example, in the array [1,2,3], the subarrays include [1], [2], [3], [1,2], [2,3], and [1,2,3].
We start with a monitor whose dimensions are a × b. Both values are integers. We want to shrink this monitor so that the new dimensions keep the exact aspect ratio x : y.
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 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).
This problem gives us the root node of a Binary Search Tree, abbreviated as BST, and asks us to find the minimum absolute difference between the values of any two distinct nodes in the tree.
We are asked to analyze a two-player game on an n × n chessboard. Petya and Gena take turns placing knights such that no knight can threaten another. A knight threatens positions in its standard L-shaped moves.
Please provide the missing problem number or title you want the guide for. Your prompt contains the formatting/template
The problem asks us to count the number of ways to fill an array of size ni with positive integers such that the product of all elements equals ki. Each query in the input array queries is independent, meaning we compute the answer for each (ni, ki) pair separately.
The problem asks us to calculate the average daily percentage of posts that were removed after being reported as spam. We are given two tables: Actions and Removals.
Yesterday the Gauls defeated n Roman soldiers, and n is guaranteed to be a prime number. Today they defeated m soldiers, where m n. We need to decide whether m is exactly the next prime number that comes immediately after n. The key detail is the phrase "next prime".
The problem gives us an m x n binary matrix, where every element is either 0 or 1. We are allowed to choose any set of columns and flip them. Flipping a column means changing every 0 in that column to 1, and every 1 to 0.
This problem asks us to query a database table named World and return a subset of countries that qualify as big countries.
This problem is asking us to assign a set of jobs, each with a specific time requirement, to k workers such that every job is assigned to exactly one worker, and we minimize the maximum total working time among all workers.
We are given a rectangular chocolate bar with integer width _W_ and height _H_. Bob breaks the chocolate multiple times along vertical or horizontal lines that go from one edge to the opposite edge of a piece.
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.
The problem gives an integer array nums and an integer k. We must divide the array into exactly k non-empty contiguous subarrays. Among those subarrays, each one has its own sum, and the goal is to minimize the largest subarray sum.
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 have a strip of cells, and each cell contains an integer. We may cut the strip only between adjacent cells, which splits the array into a left part and a right part. The task is to count how many cut positions produce two non-empty parts with equal sums.
The problem asks us to determine how many trailing zeroes appear at the end of n!, where n! represents the factorial of n. A factorial is defined as: For example: - 5!
The problem is asking us to compute cumulative scores for each gender across different days in a competition. The input
We are given a decimal string and an operation count k. Each operation looks for the leftmost occurrence of the substring "47". Suppose the substring "47" starts at position x using 1-based indexing. If x is odd, we replace both digits with '4', so "47" becomes "44".
Each person points to exactly one other person. If someone learns the news, they call the person they point to, who then calls the next person, and so on. We may add extra directed edges of the form x -> y, meaning person x must also call y.
The problem asks us to assign a rank to every element in a matrix while preserving ordering relationships inside rows and columns. For any two elements that share the same row or the same column: - If one value is smaller, its rank must also be smaller.
Each walrus builds a skyscraper whose height changes linearly over time. Walrus i starts with height a[i] and gains b[i] floors every minute, so at time t its height equals: $$hi(t) = ai + bi cdot t$$ For every query [l, r, t], we must find an index inside that interval whose…
We start with a rectangle drawn on grid paper. Only the border matters, not the interior. Players repeatedly draw a strictly smaller rectangle inside the previous one.
The problem asks us to convert a binary matrix into a Quad-Tree representation. A Quad-Tree is a recursive tree structure where every internal node has exactly four children, each representing one quadrant of the current square region.
The problem gives us a string s that contains only the characters 'a' and 'b'. In one operation, we are allowed to remov
We are given an integer array flowers, where each element represents the beauty value of a flower in a line. We may remove any flowers we want, while preserving the relative order of the remaining flowers. After removals, the remaining sequence must form a valid garden.
The problem asks whether a given integer n can be expressed as the sum of distinct powers of three. A power of three is any number of the form: where x is a non-negative integer. That means the valid powers are: - 3^0 = 1 - 3^1 = 3 - 3^2 = 9 - 3^3 = 27 - and so on.
We have exactly seven heroes and three bosses. Each boss gives some amount of experience, and every hero assigned to that boss receives an equal share rounded down. If a boss gives x experience and its team has k heroes, then every hero in that team receives x // k.
This problem asks us to transform a given sentence into a fictional language called Goat Latin, following a specific set of string manipulation rules. The input is a string called sentence, where words are separated by a single space.
The problem asks us to rearrange the rows of a Genders table in a specific repeating order while maintaining internal so
We are given up to one hundred thousand points on a 2D plane. For every unordered pair of points, we must compute the squared Euclidean distance between them and add all those values together.
The problem provides two traversal orders of the same binary tree: - inorder, which follows the order: left subtree, root, right subtree - postorder, which follows the order: left subtree, right subtree, root We must reconstruct the original binary tree and return its root node.
We are given a collection of ticket pieces. Each piece is a number, representing the fragment of a ticket that was originally divisible by three. The problem asks us to reconstruct the maximum number of lucky tickets we can from these pieces.
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.
We are given a rectangular grid representing a sheet of graph paper with _n_ rows and _m_ columns. Some of the squares are shaded, marked by *, and the rest are unshaded, marked by ..
The problem asks us to determine the minimum number of semesters required to complete n courses when there are prerequis
The problem asks us to design a data structure that continuously receives integers from a stream and can efficiently return the median of all numbers seen so far. The median is defined as the middle element in a sorted list.
The problem asks us to compute a clumsy factorial for a given positive integer n. A standard factorial multiplies all integers from n down to 1, but the clumsy factorial modifies the operations: instead of multiplying all numbers, it cycles through '', '/', '+', and '-' in…
We are given a permutation A of numbers from 1 to n. For every value i, we know a number b[i]. This number describes how many elements appear before i in the permutation and are at least i + k. The condition is attached to the value itself, not to the position.
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$.
The problem asks us to find the length of the longest substring that appears at least twice in a given string s. A substring is a contiguous sequence of characters inside a string. The repeated substrings may overlap with each other, which is an important detail.
This problem is a classic concurrency synchronization task. We are given a class FooBar with two methods, foo() and bar().
This problem asks us to analyze relationships between customers, their contacts, and invoices. We are given three tables: Customers, Contacts, and Invoices. The Customers table identifies each customer by customerid along with their name and email.
The problem is asking us to filter and sort a list of restaurants based on multiple criteria. Each restaurant is represe
The problem asks whether the characters of a given string can be rearranged to form a palindrome. A palindrome is a string that reads the same forward and backward. Examples include "racecar", "abba", and "a".
The problem asks us to count the number of good triplets in an integer array arr based on three difference constraints a, b, and c.
This problem asks us to determine the first day each player logged into a game based on a table called Activity. Each row of this table contains a playerid, the deviceid used, the eventdate on which the player logged in, and the number of gamesplayed during that session.
Each camel stands at a unique coordinate on a number line. A camel at position x spits exactly toward position x + d. If another camel stands there, it gets hit. We need to determine whether there exists a pair of camels such that each one hits the other.
The problem gives us a directed acyclic graph, usually abbreviated as a DAG. The graph contains n nodes labeled from 0 to n - 1. The graph is represented as an adjacency list, where graph[i] contains all nodes that can be reached directly from node i.
This problem asks us to determine whether a given array of integers is monotonic. An array is considered monotonic if it is entirely non-decreasing (monotone increasing) or entirely non-increasing (monotone decreasing).
This problem gives us a directed acyclic graph representing course dependencies. Each course is a node, and a prerequisi
This problem requires designing a specialized stack data structure, called CustomStack, that not only supports the usual
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.
The problem is asking us to determine the number of posts that were reported yesterday grouped by the reason for the report.
The input is a tiny arithmetic expression written as a three-character string. The first and third characters are digits from 0 to 9, and the middle character is either + or -. The task is to evaluate the expression and print the resulting integer.
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 perform in place string compression on an array of characters. The input is not a string object, but a mutable array named chars, where each element is a single character. The compression rule is based on groups of consecutive repeated characters.
The problem asks us to count how many contiguous, non-empty subarrays have a maximum element that lies within the inclusive range [left, right]. A subarray is a continuous segment of the original array. For every possible subarray, we look at its maximum value.
The input describes an undirected tree with n cities. Since the graph is a tree, there are exactly n - 1 edges and there is a unique simple path between every pair of cities. The problem asks us to examine every possible connected subset of cities.
The problem asks us to compute the top five average score for each student given a list of [ID, score] pairs. Each ID represents a unique student, and score represents a single score they received.
This problem asks us to compute the complement of a base-10 integer by flipping every bit in its binary representation. For instance, if the input n is 5, its binary form is 101. Flipping each 0 to 1 and each 1 to 0 produces 010, which equals 2 in decimal.
The problem asks us to design an efficient cache that follows the Least Recently Used, or LRU, eviction policy. A cache stores a limited number of key-value pairs.
We are asked to divide an island into connected territories for multiple parties. The island is represented by two rectangles placed side by side: one of size a by b and another of size c by d.
The problem gives us a string s that represents a license key. The string contains uppercase letters, lowercase letters, digits, and dashes. The existing dashes are only separators and do not necessarily represent the correct final grouping.
The problem describes a town containing n people labeled from 1 to n. Among these people, there may exist a special person called the town judge. The judge must satisfy two strict conditions: 1. The judge trusts nobody. 2. Every other person trusts the judge.
We are given a sequence of nails in the plane, each with integer coordinates, and a collection of straight rods. The nails define the vertices of a closed polyline that only moves along horizontal or vertical segments.
This problem asks us to compute a researcher's h-index from a sorted list of citation counts. The input array citations is sorted in non-decreasing order, meaning the citation counts appear from smallest to largest.
The problem presents an array nums of length n that is a permutation of integers from 0 to n-1. A global inversion is defined as any pair (i, j) such that i < j and nums[i] nums[j], meaning the earlier element is larger than a later element anywhere in the array.
The problem gives an array called temperatures, where each element represents the temperature recorded on a specific day. For every day, we must determine how many days in the future we need to wait until a warmer temperature appears.
This problem takes place on an infinite two dimensional grid. You begin at coordinate (0, 0) and want to reach a destination called target. At the same time, several ghosts also move on the grid from their own starting positions.
The problem gives the root node of a binary tree and asks us to invert the tree. Inverting a binary tree means swapping the left and right child of every node in the tree.
The problem asks us to find the maximum possible score of a path from the top-left corner (0, 0) to the bottom-right corner (m-1, n-1) of a 2D grid. Each cell in the grid contains an integer value, and the score of a path is defined as the minimum value along that path.
The problem asks for the minimum sum of any falling path through an n x n integer matrix. A falling path is defined as a sequence of elements starting from any element in the first row and moving row by row to the last row.
The problem gives us a list of words and a target pattern string. We need to determine which words follow the exact same structural character relationship as the pattern.
The problem asks us to clean and aggregate sales data from a Sales table. Each row contains a unique saleid, a productna
The problem is a variant of the classic "Sokoban" puzzle. You are given a grid representing a warehouse, where a player
This problem asks us to triangulate a convex polygon in such a way that the total triangulation score is minimized. We are given an array values, where each element represents the value assigned to a vertex of the polygon.
This problem asks us to convert a non-negative integer n into its representation using base -2, instead of the usual positive bases such as base 2, base 10, or base 16. In standard binary representation, numbers are written as powers of 2. For example: which becomes "1101".
In this problem, we are given a binary array called bits. The array represents a sequence of encoded characters using the following rules: - A one-bit character is represented by a single 0 - A two-bit character is represented by either 10 or 11 The array is guaranteed to end…
This problem asks us to reconstruct a target string by repeatedly applying a smaller string called stamp. We begin with a string s that has the same length as target, but every character is initially '?'.
The boss starts with max health and regenerates reg health every second. We own several scrolls. Each scroll can only be activated when the boss health is at most some percentage of the original health.
The problem asks us to find the optimal location for a service center on a 2D map such that the total Euclidean distance
This problem asks us to determine whether a given positive integer num is a perfect number. A perfect number is defined as a number whose sum of positive divisors, excluding the number itself, equals the number.
This problem asks us to count how many different valid paths exist for a robot moving through a grid while avoiding obstacles. The robot starts in the top-left corner of the grid at position (0, 0) and wants to reach the bottom-right corner at position (m - 1, n - 1).
The problem gives us an integer array nums and two fixed subarray lengths, firstLen and secondLen. We must select exactly two contiguous subarrays such that: - One subarray has length firstLen - The other subarray has length secondLen - The two subarrays do not overlap - The…
We are asked to construct a path for an ant on a tree. The tree has n vertices, with vertex 1 as the root, and n-1 edges connecting them so the graph is connected.
The problem asks us to reverse the order of words in a character array s in-place. Each word is a contiguous sequence of non-space characters, and words are separated by exactly one space.
We are asked to check whether a password entered on a 3×3 keypad is symmetric with respect to its central button. The keypad is represented as a 3×3 grid of characters, where "X" indicates a pressed button and "." indicates an unpressed one.
The problem asks us to split a given integer n into two positive integers a and b such that: - a + b = n - Neither a nor b contains the digit 0 anywhere in their decimal representation Such integers are called No-Zero integers.
We have a tank that wants to move from point A to point B along the straight segment connecting them. The tank moves with constant speed $v$, which we must choose as small as possible. There are $n$ enemy tanks placed on the plane.
The problem gives us a database table named MyNumbers that contains a single column, num. The table may contain duplicate values because there is no primary key restriction. Our task is to find the largest number that appears exactly once in the table.
The problem asks us to supply water to all houses in a village in the most cost-effective way. Each house has two options: either build a well in the house with a fixed cost, or connect the house to another house via pipes, where each pipe has its own construction cost.
We are given a chess position containing exactly four pieces on a standard 8×8 board. White has two rooks and one king, black has only a king. The position is already legal, meaning no two pieces share a square and the two kings are not adjacent.
This problem asks us to find the largest absolute difference between the values of two nodes in a binary tree, under one important condition: one node must be an ancestor of the other.
The problem asks us to find the shortest superstring that contains all the given strings in the array words as substrings.
The problem asks us to compute a "beauty" score for each element in an array nums, excluding the first and last elements. Specifically, for each index i in the range 1 <= i <= nums.length - 2, the beauty of nums[i] is determined by two conditions: 1.
We are given a year in the Gregorian calendar and a day number inside that year. The task is to determine the actual calendar date corresponding to that day number.