brain
tamnd's digital brain — notes, problems, research
43815 notes
The problem asks us to find the position on a straight street that is illuminated by the largest number of street lamps, which is referred to as its brightness.
The problem presents a simulation scenario with a row of exactly 8 prison cells, where each cell is either occupied (1) or vacant (0). Each day, the state of a cell changes based on the states of its immediate neighbors.
The problem requires computing a matrix block sum. Given a matrix mat of size m x n and an integer k, the task is to pro
The problem gives a list of money transfers between people. Each transaction is represented as [from, to, amount], meaning one person paid a certain amount to another person.
The problem asks us to divide a chocolate bar into k + 1 consecutive pieces such that we maximize the minimum total sweetness among those pieces. Each element in the input array sweetness represents the sweetness of a single chunk.
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 gives us a list of meeting intervals where each interval is represented as [start, end]. Each interval describes the time range during which a meeting occupies a conference room.
The problem gives us an n x n matrix where both rows and columns are sorted in ascending order. This means two ordering guarantees exist simultaneously: - Every row is sorted from left to right. - Every column is sorted from top to bottom.
The problem asks us to count how many valid partition points exist in an array after optionally changing at most one element to a given value k.
The problem gives us an array called salary, where each element represents the salary of an employee. Every salary value
This problem describes a frog navigating a 3-lane road of length n. The frog starts at point 0 in lane 2 and wants to reach point n. Each point along the road may have at most one obstacle in one of the three lanes, represented by the obstacles array.
The problem asks us to construct a permutation of the integers from 1 to n such that the array satisfies a special condition.
The problem asks us to determine how many starting indices in an array allow reaching the last element by performing a series of jumps defined as either odd-numbered or even-numbered.
This problem asks us to count the number of triples (i, j, k) from an integer array nums such that the bitwise AND of the three numbers at these indices equals zero. In other words, we want all combinations where nums[i] & nums[j] & nums[k] == 0.
The problem describes a path traced on a two-dimensional grid. We begin at the origin (0, 0) and move according to the values in the distance array.
In this problem, we are given an even number of people standing around a circle. Every person must participate in exactl
This problem asks us to compute the average selling price for every product based on two tables: Prices and UnitsSold. T
We are given a string representing a character's name in a game, and we can change at most k of its letters to maximize a score called euphony. The euphony is computed as the sum of bonuses for every consecutive pair of letters in the string.
The problem gives us several classes, where each class is represented as [passi, totali]. The value passi tells us how many students currently pass the exam, while totali tells us the total number of students in that class.
The problem is asking us to identify the center node of a star graph. A star graph is a very specific type of graph with n nodes: there is one node called the center, and it is connected to all other n-1 nodes.
The problem describes a classic interactive guessing game. A hidden number called pick is chosen somewhere in the range from 1 to n, inclusive. We are not allowed to access pick directly.
The problem asks us to determine, for each element in an array, how many elements in the same array are strictly smaller than it. In other words, for an element nums[i], we count all elements nums[j] such that nums[j] < nums[i] and j != i.
The problem presents a weighted undirected graph where nodes represent junctions and edges represent roads with a given length. At each junction, there is a taxi that can carry a passenger up to a maximum distance and charges a fixed cost.
This problem gives us access to a hidden function f(x, y) through an interface. We are not allowed to know or implement the formula directly. Instead, we can only call the function with positive integers x and y and observe the result.
We are given a collection of envelopes, each with a width and height. A postcard already has fixed dimensions, and we want to build the longest possible nesting chain of envelopes such that:
The problem gives us the root of a Binary Search Tree, abbreviated as BST, and asks us to transform it into a Greater Sum Tree. In a Binary Search Tree, every node follows an important ordering rule: - All values in the left subtree are smaller than the current node.
This problem asks us to combine information from two database tables and return the result in a specific format. We are
The problem asks us to design a special queue called an "Most Recently Used Queue", abbreviated as MRUQueue. Initially, the queue contains the integers from 1 to n in increasing order. The key operation is fetch(k), where k is 1-indexed. This operation does two things: 1.
The problem asks us to find the smallest contiguous substring inside string s that contains every character from string t, including duplicate occurrences. A substring must consist of consecutive characters. We are not allowed to reorder characters or skip positions.
The problem is asking us to process a string containing lowercase letters and parentheses, and remove the minimum number of parentheses so that the remaining string is valid.
The problem asks us to merge two singly linked lists in a very specific way. We are given list1 and list2, with sizes n
This problem models the spread of a virus on a two-dimensional grid. Each cell is either infected (1) or uninfected (0). The virus spreads every night from infected cells to adjacent uninfected cells in the four cardinal directions: up, down, left, and right.
The problem asks us to determine how many connected components exist in an undirected graph. A connected component is a group of nodes where every node can reach every other node through some path.
The problem asks us to rearrange an array so that all even numbers appear before all odd numbers. The relative ordering among even numbers does not matter, and the relative ordering among odd numbers also does not matter.
This problem asks us to implement a Skiplist from scratch, a probabilistic data structure that allows efficient search, insertion, and deletion operations.
This problem is asking us to calculate a retention metric from a table of player activities. Specifically, we need to determine the fraction of players who log in on the day immediately following their first login.
We are given an undirected weighted graph. Every edge connects two vertices and has a positive cost. The task is to start at vertex 1, reach vertex n, and print one shortest path. If no route exists, we print -1.
The problem asks us to implement a simplified web crawler. We are given a starting URL and access to an HtmlParser interface that can retrieve all URLs linked from a given webpage.
This problem asks us to determine which words in a given list can be typed using letters from only one row of an American keyboard. The input is an array of strings, words, where each string represents a word consisting only of English alphabet characters.
The problem provides an array of positive integers and asks us to perform operations to transform it so that two conditions are satisfied: the first element must be 1, and the absolute difference between adjacent elements cannot exceed 1.
The problem gives us a two dimensional grid called board, where each cell contains either 'X' or 'O'. The goal is to modify the board in place by capturing every region of 'O' cells that is completely surrounded by 'X'.
We are given a set of small arrays and a sequence of indexes indicating how to concatenate them into one larger array. Once the large array is built in this way, the goal is to find the maximum sum of a contiguous subarray.
The problem asks us to design a logging system that controls how frequently identical messages can be printed. Each message is associated with a timestamp, and the same message is only allowed to be printed once every 10 seconds.
The problem gives us a string containing digits and the '' character. This string encodes lowercase English letters usin
This problem asks us to generate every possible unique combination of numbers from the given candidates array such that the sum of the chosen numbers equals target. There are several important details in the problem statement: - Every number in candidates is distinct.
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.
This problem asks us to design a data structure that dynamically tracks intervals on the number line. The tracked intervals are represented as half-open intervals, meaning [left, right) includes every value x such that left <= x < right.
The problem asks us to count how many contiguous subarrays of length at least three form an arithmetic sequence. An arithmetic sequence is one where the difference between every pair of adjacent elements is identical.
We are asked to maximize profit from a set of potential races in a linearly connected kingdom. Each race occupies a contiguous set of roads and provides a payment if all the roads it uses are repaired.
The problem asks us to determine how many numbers in a given array nums have an even number of digits. The input is an a
That is a long, detailed reference document with multiple required sections, complete implementations, worked traces, and test coverage. I can provide the full guide in a single response.
We are given the results of an entire Formula One season. Each race lists drivers from first place to last place. The championship winner depends on one of two ranking systems.
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].
The problem asks us to determine the minimum total cost of cutting a wooden stick into pieces at specified positions. Th
This problem gives us a special type of array called a mountain array. A mountain array strictly increases until it reaches a single peak element, then strictly decreases afterward. For example: increases up to 5, then decreases.
The problem gives us a positive integer n and asks whether its digits can be rearranged to form a power of two. The rearrangement may keep the digits in their original order or place them in any other order, but the resulting number cannot contain a leading zero.
This problem asks us to compute, for every node in a rooted tree, the smallest positive integer that does not appear in the subtree rooted at that node. We are given two arrays: parents describes the tree structure, and nums contains distinct genetic values assigned to each node.
The problem is asking us to design a custom stack-like data structure that supports two operations: pushing values onto the stack and popping the most frequent element.
The problem gives us a keyboard with four operations: - Press A, which inserts one character 'A' - Press Ctrl-A, which selects everything currently on the screen - Press Ctrl-C, which copies the selected text into a clipboard buffer - Press Ctrl-V, which pastes the clipboard…
The problem gives us an integer array nums in which the largest value is guaranteed to be unique. Our task is to determine whether this largest number is at least twice as large as every other number in the array.
The problem asks us to determine whether two strings s and t, each representing a rational number in decimal notation, correspond to the same numerical value. These numbers can be expressed as integers, finite decimals, or decimals with repeating parts denoted by parentheses.
We have n + 1 cities. The first n cities lie on the x-axis at positions (x1, 0), (x2, 0), ..., (xn, 0). One additional city is somewhere off the axis at (x_{n+1}, y_{n+1}).
The problem is asking us to sort an array of unique integers using only pancake flips. A pancake flip is defined as reversing a prefix of the array from index 0 to index k-1 for some integer k between 1 and the length of the array.
We are given the final standings of a table bowling tournament. Every participant has a unique name and an integer score. The task is not just to sort the players, but also to assign ranking labels in the style used in real tournaments.
We have two sets of points on the plane. Red points may be used as triangle vertices, blue points are obstacles. No three points are collinear, which removes all degeneracies involving points on triangle borders.
The problem asks us to count how many unique pairs of integers in the array have an absolute difference equal to k. A pair is considered valid if: - The two elements come from different indices. - The absolute difference between the two values is exactly k.
The problem asks us to determine whether a given integer n is an ugly number. An ugly number is defined as a positive integer whose prime factors are limited to only 2, 3, and 5.
The problem gives us a positive integer n and asks for the minimum number of operations required to transform it into 1.
The problem is asking us to combine two relational database tables, Person and Address, in such a way that we report each person's first name, last name, city, and state.
This problem gives us an m x n binary matrix where every cell contains either 0 or 1. For every cell in the matrix, we must compute the distance to the nearest cell containing 0. Distance is measured using Manhattan movement with four directions only: up, down, left, and right.
The problem asks us to evaluate a Lisp-like expression represented as a string. The expression can contain integers, variables, and three special operations: let, add, and mult. An expression evaluates to a single integer value.
The problem gives us a collection of stones placed on a 2D grid. Each stone occupies a unique coordinate (x, y). A stone can be removed only if there is at least one other stone that shares either the same row or the same column.
The problem asks us to determine whether subarrays of a given array can be rearranged to form an arithmetic sequence. An
The problem asks us to generate all valid triplets of students representing a country from three schools: SchoolA, Schoo
The problem describes a room containing n light bulbs, where every bulb starts in the on state. There are four buttons available, and each button flips a specific subset of bulbs. Flipping means changing on to off or off to on.
We are given several bags of cookies, where each bag contains some number of cookies. Olga wants to steal exactly one bag. After removing that bag, the total number of cookies left behind must be even so the two sisters can split them equally.
We are asked to simulate a turn-based game between two players, Simon and Antisimon, who each have a fixed integer, a and b respectively. There is a heap of n stones.
The problem asks us to identify books from a Books table that are considered unpopular based on their sales in the last year, relative to a fixed "today" date of 2019-06-23.
The problem gives us a list of intervals that are already sorted by starting value and guaranteed to be non-overlapping. Each interval represents a continuous range, written as [start, end].
The problem asks us to count how many substrings of a given string contain only one distinct character. A substring is a contiguous section of the string. For example, in the string "aaaba", the substring "aaa" is valid because every character is 'a'.
The problem is asking us to compute the total number of seats reserved for each flight given a list of flight bookings. Each booking specifies a range of consecutive flights [firsti, lasti] and the number of seats seatsi reserved for each flight in that range.
The problem is asking us to determine whether a given array nums could be the result of taking a sorted array in non-decreasing order and then rotating it by some number of positions. A non-decreasing array is one where each element is greater than or equal to the previous one.
The problem asks us to determine how many times a binary string becomes prefix-aligned during a series of bit flips. We
We have a set of points on a 2D plane representing cows, each with integer coordinates. Vasya, the shepherd, must walk a closed path around all the cows in such a way that every cow lies strictly inside the path. The goal is to minimize the number of moves needed.
The problem gives an m x n matrix and asks us to return all elements in spiral order. Spiral order means we start from the top-left corner and move in a clockwise spiral pattern: 1. Traverse the top row from left to right 2. Traverse the right column from top to bottom 3.
The problem gives an integer array nums where every value appears exactly twice except for one value that appears only once. The task is to find and return that unique value.
We are given a sequence of marks, but the subject for each mark was lost. There are only two subjects, and we know exactly how many marks belong to each one. If subject 1 must receive a marks, then subject 2 automatically receives b = n - a marks.
The problem gives us two sentences, where each sentence is represented as an array of words. We are also given a list of word pairs that define which words are considered similar. Our task is to determine whether the two sentences are similar according to the following rules: 1.
The problem gives us the root of a binary tree and asks us to identify all duplicate subtrees inside it. A subtree is defined as any node together with all of its descendants.
The problem gives us an array called heights, where each value represents the height of a student standing in a line. The school wants the students arranged in non-decreasing order, meaning heights should appear from smallest to largest, allowing duplicates.
The problem is asking us to solve a linear equation containing a single variable 'x' and integer coefficients, expressed as a string. The equation may include addition '+', subtraction '-', and the equality operator '='.
The problem asks us to determine whether a given array of integers arr represents a valid sequence from the root to a leaf in a binary tree.
We are given an absolute Unix-style path. The path is split into components by /, and every component represents either a normal directory or file name, ".", or "..". A normal name means “go into this directory or file”. The component ".
The problem asks us to find the length of the longest strictly increasing subsequence in an array of integers. A subsequence is formed by deleting zero or more elements from the array without changing the order of the remaining elements.
The problem gives us an array of strings called wordsDict, along with two distinct target words, word1 and word2. Both target words are guaranteed to exist somewhere in the array.
This problem asks us to compute the diameter of an N-ary tree. An N-ary tree is a tree where each node can have any numb
We are given two integers, _a_ and _b_, written in some unknown base _p_. Vasya wants to compute the sum _a + b_ in all valid bases and determine which base gives the sum with the largest number of digits.
This problem asks us to compute the nth Fibonacci number. The Fibonacci sequence is defined recursively. The first two numbers are fixed: Every value after that is calculated as the sum of the previous two values: Given an integer n, we must return the value of F(n).
The problem gives us the root of a binary tree and an integer targetSum. We need to count how many downward paths in the tree have values that add up exactly to targetSum. A path can begin at any node and end at any node, as long as it always moves downward from parent to child.
The problem asks us to determine common free time intervals for a group of employees based on their schedules. Each employee has a list of non-overlapping intervals representing times when they are busy.