brain
tamnd's digital brain — notes, problems, research
43815 notes
The problem gives us a database table named RequestAccepted, where each row represents a successfully accepted friend request between two users. Every record contains a requesterid, an accepterid, and the date the request was accepted.
This problem models communication in a social network where each user knows one or more languages. Two users can communicate directly if they share at least one common language.
This problem asks us to evaluate boolean expressions stored in a database table. We are given two tables: Variables, whi
The problem asks us to maximize the number of employee transfer requests that can be fulfilled under the constraint that
The problem asks us to design an authentication system that manages tokens with expiration times. Each token is valid for a fixed timeToLive seconds starting from the moment it is generated or renewed.
The problem asks us to maximize the product of an array of non-negative integers after performing at most k increment op
The problem is asking us to simulate a modified game of Snakes and Ladders on an n x n board. The board is labeled from 1 to n² in a boustrophedon pattern, which means the numbering starts from the bottom-left, alternates direction every row, and ends at the top-right.
The problem asks us to determine the maximum number of candies we can collect from a set of boxes with varying accessibi
The problem gives us a list of integers representing asteroids moving through space in a straight line. Each integer contains two pieces of information: - The absolute value represents the asteroid's size. - The sign represents the direction: - Positive numbers move to the right.
We are given an array of positive integers. For every position, we remove that element and compute the arithmetic mean of the remaining numbers. We must find all positions where the removed value itself is exactly equal to that mean. Suppose the array is [1, 2, 3, 4, 5].
The problem gives an integer array arr and asks whether there exist two different indices i and j such that: In simpler
We are tasked with counting the number of ways to cover an n × m grid using standard dominoes of size 1 × 2, where each domino can be placed either vertically or horizontally.
We are given a string s composed of lowercase letters, with length n. The task is to determine if we can rearrange the letters so that for every prime p less than or equal to n, all positions in the string that are multiples of p can contain the same character.
The problem gives us an encoded array where each element represents the XOR of two consecutive elements from an unknown original array. Specifically: We are also given the first element of the original array, first = arr[0].
The problem gives us an encoded string s that represents a potentially enormous decoded string. The decoding process works incrementally from left to right. When we encounter a letter, we append it directly to the decoded tape.
Vasya walks into a bar and sees several customers. For each customer, he only knows one piece of information: either the person’s age or the drink they ordered. He wants to determine how many people must still be checked to guarantee that nobody under 18 is drinking alcohol.
We are given a string made only of '0' and '1'. Each character represents the team of a football player standing in a line. A dangerous situation happens if at least seven consecutive players belong to the same team.
We are asked to color a collection of intervals on the number line such that no three intervals with the same color form a "triple overlap pattern.
The task is to normalize the case of a single word so that either all letters are lowercase or all are uppercase.
The problem asks us to count how many distinct phone numbers of length n can be generated by moving a chess knight across a numeric keypad. The keypad layout looks like this: A knight moves in an L-shape. From any current digit, it can jump only to specific other digits.
The problem asks us to find a subsequence of a given integer array nums such that the sum of that subsequence is as close as possible to a given integer goal.
The problem asks us to design a data structure that continuously receives integers from a stream and returns the average of the most recent values within a fixed-size sliding window. A sliding window means that we only care about the latest size elements.
The problem gives an array called height, where each element represents the height of a vertical bar in an elevation map. Every bar has width 1. After rainfall, water may become trapped between taller bars. The task is to compute the total amount of water that can be trapped.
The problem describes a plank of length n on which ants are walking either to the left or to the right at a constant spe
The problem asks us to determine whether a given string represents a valid IPv4 address, a valid IPv6 address, or neither.
This problem asks us to find the largest axis-aligned plus sign made entirely of 1s in an n x n binary grid. Initially, every cell in the grid contains 1. However, some positions are marked as mines, meaning those cells contain 0.
This problem gives us two Quad-Trees, where each tree represents a binary matrix containing only 0s and 1s. Our goal is to compute the logical bitwise OR of the two matrices and return the result as another Quad-Tree. A Quad-Tree is a recursive spatial data structure.
We are asked to plan snow purchases over n days from m companies, ensuring we buy exactly W cubic meters each day. Each company produces a fixed daily amount w[i], but the cost of all snow from that company decreases linearly: c[i] on day 1, c[i] - a[i] on day 2, and so on.
In this problem, we are given an n x n board where each cell contains one of four possible values: - 'E', the ending position located at the top-left corner - 'S', the starting position located at the bottom-right corner - A digit character '1' through '9', representing points…
This problem is an interactive problem. We do not receive the actual binary array directly. Instead, we can only gather information through the ArrayReader API. The hidden array nums contains only 0 and 1.
The problem gives a list of time points in 24-hour clock format, where every time is represented as a string in the form "HH:MM". Your task is to determine the smallest difference in minutes between any two time points in the list.
The problem provides an array of pairs, where each pair [xi, yi] indicates that xi is either an ancestor of yi or yi is an ancestor of xi in a rooted tree. The key challenge is to determine how many different rooted trees satisfy all given pairs.
We have an n × m grid. Some entire rows are empty, some entire columns are empty, and every empty cell belongs to at least one of those empty rows or empty columns. All remaining cells contain oil.
The problem gives us a two dimensional grid representing a forest. Every cell contains one of three possible values: - 0 means the cell is blocked and cannot be entered. - 1 means the cell is empty and can be walked through.
We have several jars of honey, and each jar starts with some amount of honey. Winnie repeatedly chooses the jar that currently contains the most honey. When Winnie picks a jar, two things may happen.
The problem gives us a string representing a mathematical expression containing non-negative integers, spaces, and the four operators +, -, , and /. Our task is to evaluate the expression and return the resulting integer value.
The problem asks us to transform a binary tree into a flattened structure that behaves like a singly linked list. The transformation must happen in-place, meaning we are not supposed to create an entirely new tree or list structure.
This problem asks us to select a subsequence of strings from the input array arr and concatenate them together such that the resulting string contains only unique characters. Among all valid concatenations, we must return the maximum possible length.
We start with four integers on the board. We also know the exact sequence of three operations that must be applied, where each operation is either addition or multiplication.
The problem asks us to transform a binary tree into its "upside-down" version. In more precise terms, we are given a binary tree where every right node either has a left sibling or is absent, and no right node has children.
We receive a single string containing uppercase and lowercase English letters. The task is to transform this string according to three rules. First, every vowel must be removed. The vowels in this problem are A, O, Y, E, U, I in both uppercase and lowercase forms.
The problem asks us to group the nodes of a binary tree by their vertical columns and return those groups from left to right.
We start with a row of n panels, all turned OFF. The target password is another configuration where exactly k specific positions must be ON and every other position must remain OFF. One operation chooses a segment of consecutive panels whose length belongs to the array a.
The problem gives us an integer array arr and an integer k. We are allowed to partition the array into contiguous subarrays where each subarray has length at most k.
The problem gives us a string s and a list of index pairs called pairs. Each pair [a, b] means we are allowed to swap the characters at positions a and b. The important detail is that swaps can be performed any number of times. This changes the nature of the problem completely.
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 problem presents a stream of points in a 2D plane and asks us to design a data structure that supports two operations efficiently: adding points and counting squares.
This problem describes a two player game played on an array of integers. The numbers are written on a chalkboard, and players take turns erasing exactly one number. Alice moves first, then Bob, and both players play optimally. The key rule is unusual.
This problem asks us to generate every possible subset of a given array of unique integers. A subset is any selection of elements from the array, including the empty subset and the subset containing every element.
This problem asks us to analyze user interaction data stored in the SurveyLog table and determine which question has the highest answer rate. The table records actions performed by users during survey sessions. Every row represents a single interaction with a question.
We have two arrays representing the order of students in a line. Array a is the desired arrangement, and array b is the current arrangement. In one operation we may swap two neighboring students. We must output any sequence of adjacent swaps that transforms b into a.
This problem asks us to minimize the total number of ship trips required to deliver boxes from storage to ports, while r
We have an array whose values are always at most 10000. Two operations must be processed online. The first operation adds a value d to every element inside a segment [l, r].
This problem requires calculating the day one retention metric for a game based on user activity data. The input is an Activity table, where each row represents a login session of a player on a particular day, including the device used and the number of games played.
This problem asks us to determine whether a binary tree contains at least one valid root-to-leaf path whose node values add up to a given target sum. A binary tree consists of nodes where each node can have a left child and a right child. Each node also stores an integer value.
The problem defines an infinite cyclic string built from the lowercase English alphabet: This means the sequence continues forever, and after 'z' comes 'a' again. Any substring that follows this cyclic ordering exists somewhere in the infinite wraparound string.
The problem provides a tree rooted at node 0, represented in two parallel arrays: parent and value. The parent[i] array
The problem asks us to design two operations for a Binary Search Tree, abbreviated as BST: - serialize(root) converts the BST into a string representation. - deserialize(data) reconstructs the exact same BST from that string.
We are simulating a simplified version of the party game "Boom" with multiple teams and cards. There are n teams, each with two players. Each player has an ability to explain words (a) and an ability to understand words (b).
The problem asks us to determine whether a given set of points in a 2D Cartesian plane all lie on a single straight line. The input is a list of integer coordinates, where each coordinate [x, y] represents a point.
We are asked to compute the expected lifespan of a dynamic particle moving on a 2D grid with static obstacles. The grid has n rows and m columns. Static particles occupy certain cells, never sharing a row, column, or diagonally adjacent cell.
We are given the positions of two chess pieces on a standard 8 × 8 board, one rook and one knight. Their starting positions are guaranteed to be safe, meaning the rook does not attack the knight and the knight does not attack the rook.
The problem asks us to implement a URL shortening service, similar to TinyURL. Given a long URL, our system should generate a short, unique URL that maps back to the original URL. When the short URL is accessed, the system should return the original long URL.
This problem asks us to compute several descriptive statistics-minimum, maximum, mean, median, and mode-from a very large sample of integers ranging from 0 to 255.
We start with a lowercase string and may delete at most k characters from it. The remaining characters must stay in their original order, since deleting characters creates a subsequence.
The problem gives us a strictly increasing array called target and an integer n. We are also given access to a stream of integers starting from 1 and ending at n. The numbers arrive in order, and once a number is skipped, we cannot go back to it.
This problem gives us a string s and an integer k. We are allowed to repeatedly perform one operation: - Choose one of the first k characters of the string. - Remove that character from its current position. - Append it to the end of the string.
This problem asks us to determine the maximum overlap between two binary square matrices (img1 and img2) when one matrix is translated over the other. Each matrix contains only 0s and 1s, where 1 represents a filled pixel and 0 represents an empty pixel.
The problem gives us an array nums with exactly 2n elements. The structure of the array is guaranteed to follow a very specific pattern: This means the first half of the array contains all the x values, and the second half contains all the y values.
The problem asks us to compute the n-th number in the Tribonacci sequence. The Tribonacci sequence is very similar to the Fibonacci sequence, except that instead of summing the previous two numbers, each value is formed by summing the previous three numbers.
The problem asks us to rearrange the rows of a Genders table in a specific repeating order while maintaining internal so
The problem gives us a numeric string s of even length and two operations that can be performed any number of times in a
We are asked to enumerate all ways to split n toys into piles, starting from a single pile containing all toys. The toys are numbered from 1 to n, and the order within a pile or between piles does not matter for uniqueness beyond the actual grouping.
This problem asks us to examine the smallest number in the input array and determine whether the sum of its digits is odd or even. We are given an integer array nums. The task consists of three clear steps: 1. Find the minimum integer in the array. 2.
The problem can be restated as simulating bullets flying along the positive _Z_ axis at given coordinates on a 2D shooting plane (_XOY_). Each bullet may hit one of multiple rectangular targets floating at distinct heights along the _Z_ axis.
We need to build an undirected graph on n cities such that no triangle exists. A triangle means three distinct cities where every pair is directly connected.
This problem gives us an n x n grid where each cell represents the height of a building in a city. The city can be viewed from four directions: north, south, east, and west. From these viewpoints, the skyline is determined by the tallest building visible in each row or column.
The problem is asking us to compute cumulative scores for each gender across different days in a competition. The input
This problem asks us to perform a postorder traversal on an n-ary tree. In a binary tree, each node has at most two children. In an n-ary tree, each node can have any number of children. Every node contains a value and a list of child nodes. A postorder traversal means: 1.
The problem gives us n nodes labeled from 0 to n - 1. For every node i, we are told which node is its left child and which node is its right child through the arrays leftChild and rightChild. If leftChild[i] = x, then node x is the left child of node i.
The problem asks us to sort a singly linked list using the insertion sort algorithm. Unlike array sorting problems where elements can be accessed directly by index, linked lists require sequential traversal, so insertion operations behave differently and require careful…
The problem asks us to find the smallest positive integer divisor for a given array nums such that when each element of
We are asked to reconstruct the missing result of a round-robin tournament. There are _n_ participants, and every participant plays against every other participant exactly once.
We are asked to find the minimum distance Shapur must travel to visit all cities at least once. The cities are connected in a tree structure, meaning there are exactly $n-1$ bidirectional roads and a unique path between any two cities.
The problem asks whether it is possible to partition a deck of cards, represented as an integer array deck, into groups such that each group contains exactly x cards, all of which have the same integer value, and x is greater than 1.
We are given a set of atoms with known atomic numbers and a target set of atoms we want to produce using fusion. Each fusion operation combines exactly two atoms into one, and the resulting atom’s atomic number is the sum of the two original numbers. We cannot split atoms.
We are given a string of 2n digits. The digits are processed strictly from left to right. At every step, either Homer or Marge takes the current leftmost digit and appends it to their own number. By the end, both players must have taken exactly n digits.
The Sliding Puzzle problem presents a 2 x 3 board containing five numbered tiles from 1 to 5 and a blank space represented as 0.
The problem requires us to process a string word that contains both lowercase English letters and digits. We are asked to extract all the sequences of digits as integers, ignoring any non-digit characters.
It looks like your prompt accidentally concatenated two problems. I will answer the second one, LeetCode 173 - Binary Search Tree Iterator, following your required format.
The problem is asking us to design a system that tracks tweets by their timestamp and allows querying the number of tweets in specific time intervals, split according to a frequency (minute, hour, or day).
This problem asks us to calculate, for every month in the year 2020, the percentage of drivers who actually worked durin
The problem requires designing a data structure that can efficiently maintain and retrieve the first unique integer in a
We are asked to organize a company party such that no group contains both a manager and their subordinate, directly or indirectly. The input describes each employee's immediate manager: a number from 1 to n, or -1 if they have no manager.
This problem gives us a directed acyclic graph representing course dependencies. Each course is a node, and a prerequisi
The problem describes a circular route containing n gas stations. At each station i, you can collect gas[i] units of fuel. Traveling from station i to station (i + 1) % n consumes cost[i] units of fuel.
This problem asks us to determine how many strings in the words array are consistent with a given set of allowed charact
This problem gives us a tree with n nodes numbered from 0 to n-1, rooted at node 0. Each node has an associated value from the array nums, and the tree structure is given as a list of edges.
The problem asks us to determine how many items in a list satisfy a given rule. Each item is represented as a list of three strings: its type, color, and name. The rule is given as two strings: ruleKey and ruleValue.
The problem asks us to find the length of the longest strictly increasing contiguous segment in an array. The key detail is that the subsequence must be continuous, which means the elements must appear next to each other in the original array.