brain
tamnd's digital brain — notes, problems, research
43815 notes
The problem asks us to cover a sporting event that lasts time seconds using a set of video clips. Each clip is defined by its start and end times, [starti, endi], and clips can overlap or extend beyond each other.
The problem gives us a table named Friendship, where every row represents a friendship relationship between two users. E
We have n walruses arranged in a circle. The presenter starts with m chips and distributes them in order. Walrus 1 receives 1 chip, walrus 2 receives 2 chips, and so on up to walrus n, after which the cycle repeats again from walrus 1.
This problem asks us to identify all sellers who did not make any sales during the year 2020. We are given three databas
This problem asks us to modify a binary tree by removing every subtree that does not contain at least one node with value 1. A subtree consists of a node and all of its descendants. If an entire subtree contains only 0 values, then that subtree should be deleted from the tree.
You are given two strings, a and b, where each string represents a binary number. A binary number contains only the characters '0' and '1'. The task is to add these two binary numbers together and return the result as another binary string.
This problem is an interactive backtracking problem where we must control a robot without directly seeing the room layout. Unlike traditional grid traversal problems, we are not given access to the actual room matrix during execution.
The problem asks us to transform a given integer array nums into a strictly increasing array using the minimum number of operations. An operation consists of incrementing any element of the array by 1.
The problem gives us an integer array arr and asks us to replace every element with the greatest value that appears some
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.
We are given the heights of soldiers standing in a circle. Two soldiers can form a reconnaissance unit if they stand next to each other and their height difference is as small as possible among all neighboring pairs.
The problem gives us an integer array nums, a maximum allowed absolute value limit, and a target sum called goal.
We are looking at finite strings over an alphabet of size k. For every such string, define a special value: Take all substrings of the string. Among them, some substrings can also appear as a subsequence in a non-contiguous way.
This problem asks us to delete a node from a singly linked list, but with an unusual restriction: we are not given access to the head of the list. Instead, we are only given a reference to the node that should be deleted.
This problem asks us to analyze banking transaction data and determine which users currently have a balance greater than 10000. We are given two database tables: The Users table stores account information.
The problem gives us two database tables, Users and Transactions, and asks us to compute the final account balance for every user after applying all recorded transactions. The Users table contains the starting credit balance for each user.
The problem asks us to implement a circular queue, a fixed-size queue where the end wraps back to the start to efficiently reuse empty space.
The game is played on a one-dimensional stripe of squares, each either black or white. Vasya paints the initial configuration, and Petya can then perform moves to achieve an alternating pattern, where no two adjacent squares share the same color.
We are given all pairwise unions of some hidden disjoint sets. The original sets themselves are not shown. Suppose the hidden sets are $S1, S2, dots, Sn$. For every pair $i neq j$, we are given the set $Si cup Sj$.
We have a collection of items, and every item belongs to exactly one of three equipment classes: weapon, armor, or orb. Each item has three base stats, attack, defense, and resistance, plus a capacity telling us how many residents it can hold. Residents also come in three types.
This problem asks us to determine whether a car can successfully complete a series of passenger trips without ever exceeding its seating capacity.
The problem asks us to distribute m balls into n baskets located at given positions along a line in such a way that the minimum distance between any two balls is maximized. The magnetic force between two balls is defined as the absolute difference of their positions.
We need to count integers inside the interval $[a,b]$ whose smallest divisor greater than $1$ is exactly $k$. For a number $x$, saying that its smallest divisor is $k$ means two things happen simultaneously: 1. $x$ is divisible by $k$. 2.
The problem asks us to extract all consecutive records from a Stadium table where the people count is at least 100, and the consecutive streak has a length of three or more. Each row has a unique id and a corresponding visitdate.
The problem describes a voting based ranking system where every voter ranks all teams from best to worst. Each vote is r
Each input line describes the full path of one file inside a file system. A path looks like: The disk name is the root and is not considered a folder. Every component between the disk and the file is a folder. The last component is always a file.
This problem asks us to find the longest path in a binary tree where every node along the path has the same value. The key detail is that the path length is measured in edges, not nodes.
The problem requires calculating sums of specific subsets of an integer array nums based on queries. Each query [xi, yi] specifies a starting index xi and a step yi. The sum for this query includes all elements nums[j] such that j starts at xi and increases in steps of yi (i.e.
This problem asks us to calculate the percentage of users who attended each contest. We are given two tables: Users and
This problem asks us to implement our own linked list data structure from scratch without using any built in linked list library.
The problem asks us to count how many arithmetic subsequences exist inside a given integer array nums. An arithmetic sequence is a sequence where the difference between consecutive elements is constant. The sequence must contain at least three elements.
The problem asks us to calculate the sum of all odd-length subarrays of a given array of positive integers. A subarray is any contiguous sequence of elements from the original array.
We are asked to compute the maximum number of “tentacles” that can traverse a cylindrical grid from the leftmost column to the rightmost column, given capacities for every corridor connecting adjacent cells.
The problem gives us a string called licensePlate and an array of candidate words called words. We must find the shortest word that satisfies all the letter requirements contained in licensePlate. The key detail is that only alphabetic characters matter.
The problem gives us two strings, str1 and str2, which are guaranteed to have the same length. We want to determine whether it is possible to transform str1 into str2 using a sequence of character conversion operations.
The problem is asking us to count all pairs of dominoes in a list that are equivalent, where two dominoes [a, b] and [c, d] are considered equivalent if one is a rotation of the other, meaning either (a == c and b == d) or (a == d and b == c).
In this problem, we are given two arrays, quality and wage, where each index represents a worker. The value quality[i] describes how much work or contribution the i-th worker provides, while wage[i] describes the minimum amount that worker is willing to accept.
This problem is asking us to find the convex hull of a set of points on a 2D plane. The input trees is a list of coordinates where each coordinate [xi, yi] represents the location of a tree in the garden.
This problem asks us to count how many different ways a pointer can end up back at index 0 after taking exactly steps mo
Given a non-negative integer n, we must count how many times the digit 1 appears in every number from 0 through n, inclusive. The important detail is that we are not counting how many numbers contain the digit 1.
This problem asks us to determine the minimum number of cameras required to monitor all nodes in a binary tree. Each camera placed on a node can monitor its parent, itself, and its immediate children.
This problem asks us to compute a cumulative salary summary for each employee based on their monthly salaries over the year 2020. The input is a table Employee where each row contains an employee id, the month (1 through 12), and the salary for that month.
The problem describes a repeating weekly saving pattern. Hercy deposits money into the LeetCode bank every day, and the amount increases in a structured way. On the very first Monday, he deposits 1 dollar. Each following day in the same week increases by 1.
We need to build a lowercase string of length n that satisfies a special condition on repeated letters. For every character, we look at all positions where it appears.
We are given a string made of two characters, C and P. Each character represents one object hanging on the wall. C means postcard, P means photo. Polycarpus removes objects from left to right. He cannot skip positions, and at any moment he may carry only one type of object.
The problem asks us to design a custom data structure that behaves like a map from strings to integers, while also supporting efficient prefix-based sum queries. There are two operations: 1. insert(key, val) This operation stores a string key with an integer value.
We are given several force vectors acting on a body in three-dimensional space. Each vector has three components: its effect along the x-axis, y-axis, and z-axis. A body is in equilibrium only if the total force acting on it is zero in every direction.
This problem asks us to select exactly three items from a store while satisfying both an index ordering condition and a
This problem asks us to remove duplicate values from a sorted singly linked list so that every distinct value appears exactly once.
The problem asks us to determine the minimum number of semesters required to complete n courses when there are prerequis
This problem models processes in an operating system as a tree structure. Every process has exactly one parent, except for the root process, which has no parent and is identified by ppid[i] = 0.
The game records a sequence of rounds. In each round, one player either gains or loses some number of points. At the end, the player with the highest total score should win.
The problem gives us an undirected and connected graph with n nodes labeled from 0 to n - 1. The graph is represented as an adjacency list, where graph[i] contains all nodes directly connected to node i.
We start with an n × m chessboard. The top-left cell is black, so the coloring alternates exactly like a normal chessboard. Only the initially black cells participate in the repainting process.
The problem asks us to process a singly-linked list and, for each node, determine the value of the next node that has a strictly larger value.
This problem asks us to coordinate three independent threads so that they execute in a strict order, regardless of how the operating system schedules them. We are given a class with three methods, first(), second(), and third().
This problem asks us to compute the maximum nesting depth of parentheses in a valid parentheses string. A valid parentheses string, often abbreviated as VPS, is a string where every opening parenthesis '(' has a matching closing parenthesis ')', and the parentheses are…
The problem gives an integer array nums where every value appears exactly twice, except for two numbers that appear only once. The task is to find those two unique numbers and return them in any order.
We want to cook soup using several ingredients that must appear in a fixed ratio. If the recipe says the proportions are a1, a2, ..., an, then the final soup must contain:
The problem asks us to generate every possible subset of a given integer array. A subset is any selection of elements from the array, including the empty subset and the subset containing all elements.
The problem gives us an array of non-negative integers and a starting index. From any position i, we are allowed to jump
This problem asks us to generate the shortest possible string that guarantees a safe will unlock at some point while typing it. The safe password has exactly n digits, and each digit can be any value from 0 to k - 1. The safe does not validate the entire entered sequence at once.
We stack cubes one by one. Every cube is axis-aligned, and its projection on the ground is a square. Since the cubes are actual cubes, the side length is determined by the square base.
The problem provides an array of exactly four digits. Using each digit exactly once, we must construct the latest possible valid 24-hour time in the format "HH:MM".
The problem asks us to calculate the sum of beauty for all substrings of a given string s. The beauty of a substring is defined as the difference between the highest frequency and the lowest frequency of any character that occurs in that substring.
We are given up to 100 triangles on the plane. Each triangle represents a black spot on a white square. Triangles may overlap, intersect, or even completely cover one another. The task is to compute the perimeter of the union of all black regions.
The problem asks us to minimize the length of a run-length encoded string after deleting at most k characters from the o
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 sorted integer array where every value appears exactly twice, except for one value that appears only once. Our task is to find that unique value. The important detail is that the array is already sorted.
The problem asks us to find an index in the array such that the sum of all elements strictly to the left of that index is equal to the sum of all elements strictly to the right of that index. More formally, for an index i: - Left sum = nums[0] + nums[1] + ...
The problem defines a special binary grammar sequence that grows row by row. The first row contains only a single value: Every later row is generated from the previous one using these rules: - Replace every 0 with 01 - Replace every 1 with 10 This means the rows evolve like…
The problem gives us an n x n matrix called grid. Each cell grid[i][j] represents how many 1 x 1 x 1 cubes are stacked vertically at position (i, j) on a flat surface.
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.
In this problem, we are given n friends, where n is always even. Every friend ranks all other friends in order of preference. The earlier someone appears in a person's preference list, the more that person is preferred. We are also given a final pairing arrangement.
We have a source string s1, which represents the headline of one newspaper. We may take as many copies of this headline as we want and concatenate them together.
This problem asks us to place introverts and extroverts inside an m x n grid in a way that maximizes the total happiness score. Every grid cell can either remain empty, contain one introvert, or contain one extrovert.
We have several accumulators, each storing some amount of energy. We are allowed to move energy between them, but every transfer wastes a fixed percentage. If we send x units from one accumulator, the sender loses all x, while the receiver only gains x (100 - k) / 100.
This problem asks us to reconstruct an array that was compressed using a simple run-length encoding format. The input array nums always contains an even number of elements.
This problem asks us to find the lowest common ancestor, usually abbreviated as LCA, of two nodes in a binary tree. Unli
Each quarry contributes a consecutive range of heap sizes to a standard Nim game.
We are given a stripe consisting of n squares, each containing an integer. The task is to cut this stripe into three contiguous, non-empty segments such that the sum of numbers in each segment is identical. The output is the number of valid ways to perform these cuts.
This problem asks us to construct a special ordering of all integers from 0 to 2^n - 1. The ordering must satisfy the properties of a circular Gray code sequence.
The problem gives four points in a 2D coordinate system and asks whether those four points form a valid square. The points are not provided in any guaranteed order, which means we cannot assume adjacent points or diagonally opposite points are already grouped correctly.
The problem gives a sequence of points on a 2D coordinate plane. Each point is represented as [x, y], where x and y are
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.
The problem gives us two integer arrays, nums1 and nums2, and asks us to return their intersection. The intersection consists of all values that appear in both arrays. However, the result must contain only unique elements, even if a number appears many times in either array.
This is a SQL database problem where we need to identify countries whose average call duration is strictly greater than
This problem asks us to convert a fraction, represented by an integer numerator and an integer denominator, into its decimal string representation. If the decimal expansion contains a repeating fractional sequence, we must enclose the repeating part in parentheses.
We are given a grid of size n × m, representing a board where Gennady has placed 28 domino chips. Each domino occupies exactly two adjacent squares, and the squares of the same domino are marked with the same letter, while different dominoes have different letters.
Each student points to exactly one other student, the person they consider their best friend. We may create a pair (a, b) only if either a chose b or b chose a. Every student can belong to at most one pair.
The problem gives us an array of coin values, where each coin can be used at most once. We are asked to determine the maximum number of consecutive integer values that can be formed starting from 0.
The problem asks us to group strings based on a special equivalence property. Specifically, two strings are special-equivalent if you can swap characters at even indices among themselves and characters at odd indices among themselves any number of times to make the two strings…
We are given an array of worm lengths. Each position represents a different worm form, and we need to find three distinct indices such that the length at one index equals the sum of the lengths at the other two indices.
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.
In this problem, we are standing at a fixed position on a 2D plane, represented by location = [posx, posy]. Around us, there are multiple points, each with integer coordinates. We are allowed to rotate in place, but we cannot move.
We have 2N - 1 boxes. Every box contains two numbers, the number of apples and the number of oranges inside it. We must choose exactly N boxes such that the chosen set contains at least half of all apples and at least half of all oranges across every box.
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).
This problem asks us to design a calendar system that supports adding time intervals and reporting the highest number of overlapping events seen so far. Each booking is represented as a half open interval [startTime, endTime).
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.
This problem asks us to compute the number of distinct combinations of coins that can sum to a target amount. We are given an array coins, where each value represents a coin denomination, and an integer amount, which represents the target sum we want to form.