brain
tamnd's digital brain — notes, problems, research
43815 notes
The problem asks us to identify transactions that are potentially invalid based on two rules. First, any transaction with an amount greater than $1000 is invalid.
The problem asks us to count how many integers in the range [1, n] contain at least one repeated digit. A repeated digit means that some digit appears more than once in the number. For example, 11 has a repeated 1, 100 has repeated 0, and 121 has repeated 1.
We are given a 2D grid of size _n_ by _m_, each cell either containing a star * or empty .. The task is to locate constellations shaped like a cross.
The problem gives us an array of strings called words and an integer k. Each string represents a word, and words may appear multiple times in the array. Our task is to return the k most frequent words. The result must follow two ordering rules.
The problem gives us an array of k sorted linked lists. Each linked list is already sorted in ascending order, and our task is to combine all of them into one single sorted linked list. A linked list node contains a value and a pointer to the next node.
This problem asks us to maximize the number of “happy” customer groups by choosing the best possible ordering of the groups. The donut shop produces donuts in batches of exactly batchSize. A fresh batch starts only when the previous batch has been completely consumed.
The problem asks us to find the length of the longest substring in which every character appears at least k times. A substring is a contiguous sequence of characters inside the original string.
The problem is asking whether it is possible to convert one string s into another string t using at most k moves, follow
We are given several sets of integers, each with an associated cost. We may choose any collection of these sets, including the empty collection. Let the number of chosen sets be $k$, and let the union of all chosen sets contain $u$ distinct integers.
We are given a string template consisting of lowercase letters and question marks. The final string must satisfy three conditions simultaneously. First, it must be a palindrome, so characters mirrored around the center must match.
The problem asks us to count how many index triplets (i, j, k) satisfy two conditions: - The indices must follow the order i < j < k - The values at those indices must sum to the given target Formally, we want: The important detail is that we are counting tuples of indices…
The problem asks us to determine whether one string can "break" another string through some permutation. Given two strin
The problem gives us a string s containing only the characters 'a', 'b', and 'c'. We may repeatedly perform a deletion operation on the string.
Each player owns a multiset of artifacts. Some artifacts are basic and can be purchased directly. Some are composite and can be crafted from several basic artifacts in fixed quantities. Whenever a player buys a basic artifact, it is added to their inventory.
We have three transformation spells that convert one material into another. The first spell turns a grams of sand into b grams of lead. The second spell turns c grams of lead into d grams of gold. The third spell turns e grams of gold into f grams of sand.
This problem asks us to generate all possible combinations of size k from the numbers in the inclusive range [1, n].
This problem asks us to minimize the number of unique integers in an array after removing exactly k elements. In other words, we are given a list arr and a number k, and we need to strategically remove k elements so that the count of distinct integers left in the array is as…
Bob experiences one event per day. A day is either a prize day or a customer day.
The problem asks us to remove vowels from a given string s. Specifically, the vowels are defined as the lowercase characters 'a', 'e', 'i', 'o', and 'u'. The input string consists only of lowercase English letters, and its length ranges from 1 to 1000.
The problem asks us to determine the optimal rotation of an array nums so that the resulting array achieves the highest possible score, where a score is defined as the number of elements that are less than or equal to their index after rotation.
We are given a one-dimensional map of a village where all the houses lie along the _x_-axis. Each house is square, specified by its center coordinate and its side length. No two houses overlap, though they may touch edges.
The problem is asking us to compute a score for a string of balanced parentheses according to a set of rules. A balanced parentheses string is one in which every opening parenthesis '(' has a corresponding closing parenthesis ')' and the pairs are properly nested.
This problem asks us to simulate a baseball scoring system with a set of unusual rules. We begin with an empty score record and process a sequence of operations one by one. Each operation either adds a new score or modifies the history of previously recorded scores.
In this problem, we are given a string that represents multiple possible words. Each position in the word may contain either a single fixed character or a set of alternative characters enclosed in curly braces.
The problem asks whether a given string s can become a palindrome after deleting at most one character. A palindrome is a string that reads the same forwards and backwards.
This problem asks us to identify whether there is a "celebrity" among n people at a party. A celebrity has a very specific property: - Every other person knows the celebrity. - The celebrity knows nobody else. We are not given the entire relationship graph directly.
The problem gives a date string in a human readable format such as "20th Oct 2052" and asks us to convert it into the st
The problem asks us to count all substrings of a given string s that contain at least one occurrence of each character '
The problem gives an array of strings and asks us to find the longest prefix shared by every string in the array. A prefix is a sequence of characters that appears at the beginning of a string.
We have a connected weighted graph of cities. Runner i starts from city i and finishes in some other city. The finish city is chosen independently for every runner, and several runners may share the same destination.
The problem asks us to determine the minimum number of moves required to identify a critical floor in a building using a limited number of eggs.
We have a burglar who can carry exactly n matchboxes. In the warehouse, there are m containers. Each container i has a_i matchboxes, and every matchbox in that container contains b_i matches.
We are given a set of islands connected by bidirectional roads. The islands form regions: each region is a connected component, and islands in different regions have no path between them.
The problem gives an array of intervals where each interval is represented as [start, end]. Each interval describes a continuous range on a number line. The task is to remove the minimum number of intervals so that the remaining intervals no longer overlap.
This problem asks whether it is possible to construct the string ransomNote using characters taken from the string magazine. Each character in magazine can only be used once, which means character frequency matters.
This problem asks us to compute the total points for each football team after a series of matches in a tournament. The scoring rules are standard: a win gives 3 points, a draw gives 1 point, and a loss gives 0 points. The input consists of two tables: Teams and Matches.
We are given two binary strings of equal length. Each character is either '0' or '1'. For every position, we compare the characters from the two strings. If the two characters are different, the resulting string gets '1' at that position.
We have a set of horizontal blind stripes of varying lengths, and our goal is to construct a rectangular blind for a window using these stripes. Each stripe can be cut into smaller pieces, but pieces cannot be shorter than a given minimum length, l.
The problem asks us to compute the ordinal day number of a year given a date in the format YYYY-MM-DD. For example, January 1st is always day 1, January 2nd is day 2, and December 31st is either day 365 or 366 depending on whether the year is a leap year.
The problem asks us to take an array of integers nums that is already sorted in non-decreasing order and return a new array containing the squares of each number, also sorted in non-decreasing order.
The problem provides a string traversal representing a preorder depth-first traversal of a binary tree, where each node is represented by its value preceded by D dashes, with D being the depth of the node in the tree. The root node has depth 0 and is not preceded by any dash.
The problem asks us to find the length of the longest contiguous subarray in an integer array nums such that the absolut
The problem describes a one-dimensional garden that stretches from position 0 to position n. At every integer position i, there is a tap that may water some interval around it.
Each viewing mode groups the inventory into pages of size ai. If the inventory contains k items, then the game shows $bi = leftlceil frac{k}{ai} rightrceil$ pages in that mode. Vasya does not know the actual value of k, only that 2 ≤ k ≤ x.
The problem asks us to format a non-negative integer so that every group of three digits is separated by a dot (.), starting from the right side of the number. For example, the number 1234567 should become "1.234.
Edit The problem gives us a string s and asks for the minimum number of insertion operations required to transform the s
The problem asks us to clean and aggregate sales data from a Sales table. Each row contains a unique saleid, a productna
The problem asks us to count all possible non-empty sequences that can be formed from a set of letter tiles, where each tile has a single uppercase letter. The input is a string tiles representing the letters available on the tiles.
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.
The problem asks us to find the longest special substring that appears at least three times in the given string s. A sub
This problem asks us to compute the overall acceptance rate of friend requests in a social network system. Two database tables are provided. The first table, FriendRequest, stores all friend requests that users sent to each other.
In this problem, we are given a circular track divided into n sectors, numbered from 1 to n. A marathon runner moves around this track in increasing numerical order, and after sector n, the runner wraps back to sector 1.
The problem asks us to design a data structure that supports efficient searches based on both a prefix and a suffix. We are given an array of words, where each word has an implicit index based on its position in the array. The WordFilter class must support two operations: 1.
This problem gives us a sorted, 1-indexed array of integers called numbers and a target integer target. Our task is to find exactly two numbers in the array whose sum equals target, then return their 1-based indices.
The problem gives us a binary number represented as a string s. Our task is to determine how many operations are require
Gerald repeatedly removes either one candy or one stone. After every move, Mike looks at how many candies and stones Gerald has already eaten. If Gerald has eaten a candies and b stones so far, Mike awards $$f(a,b) = (xa + yb) bmod p$$ points.
The problem gives us a database table named UserActivity that stores activity periods for different users. Each row cont
The problem asks us to select exactly three non-overlapping subarrays from the input array nums, where each subarray has length k. Among all valid choices, we must maximize the total sum of all elements contained in those three subarrays.
The problem gives us an integer array nums and a list of update operations called queries. Each query contains two values: - vali, the amount to add - indexi, the position in the array to update For every query, we must first update the array element: After applying the update…
Petr is standing somewhere in a line containing n people. Positions are numbered from 1 at the front to n at the back. He knows two things about his position. At least a people are standing in front of him, and at most b people are standing behind him.
We are given the current month as a string and an integer k representing how many months later a new game release will happen. The task is to determine the month after advancing exactly k months forward in the calendar.
The problem gives us an array ages, where each value represents the age of a person on a social media platform. We must determine how many friend requests are sent between people according to a specific set of rules.
The problem asks us to find a missing value from an array that originally formed an arithmetic progression (AP). An arithmetic progression is a sequence where the difference between consecutive terms is constant, i.e., arr[i + 1] - arr[i] is the same for every consecutive pair.
LeetCode 669, Trim a Binary Search Tree, asks us to modify a binary search tree so that every remaining node has a value within the inclusive range [low, high].
We have an n × m chessboard. A billiard ball moves diagonally like a bishop, but unlike a bishop it reflects off the borders of the board. When it hits a vertical wall, the horizontal component of the direction flips. When it hits a horizontal wall, the vertical component flips.
This problem asks us to find a contiguous subarray that contains only unique elements, meaning no value appears more than once inside that subarray. Among all such valid subarrays, we must return the maximum possible sum of its elements.
We start on an infinite chessboard at square (0, 0). A knight moves using the usual chess move, two cells in one direction and one in the perpendicular direction. Some squares are removed from the board, and the knight is never allowed to stand on them.
This problem asks us to determine whether a string s3 can be formed by interleaving two other strings, s1 and s2. An interleaving means we combine characters from s1 and s2 while preserving the relative order of characters within each original string.
We are given a rectangular map of size n × m, where each cell has a non-negative height. Peter wants to build cities of size a × b. To place a city, he must level the ground inside its rectangle by reducing all cells to the minimum height within that rectangle.
The problem gives us a two-dimensional grid of integers called matrix. Each position in the grid contains a value, and we are asked to find the length of the longest strictly increasing path.
This problem is asking us to determine how to write a string s on multiple lines when each character has a specific pixel width and no line can exceed 100 pixels.
The problem describes a cinema hall in Berland with K rows and K seats per row, where K is always odd. Customers come in groups of size M and request consecutive seats.
The problem asks us to compute a simple mathematical transformation on the digits of an integer. Given an integer n, we
We are given a connected undirected graph representing the road network of Bertown, where junctions are nodes and roads are edges.
We have houses numbered from 1 to n. Every house must receive a color. For each color, if we add together all house indices painted with that color, the result must be a prime number.
We are given the indices of tests that already exist in the system. Every index is a positive integer, and all indices are distinct. The task is to find the smallest positive integer that does not appear in the list.
This problem presents a maze represented as a 2D grid of size m x n where each cell is either an empty space (0) or a wall (1). A ball starts at a given position and can roll up, down, left, or right.
The problem asks us to identify all employees in a company who directly or indirectly report to the head of the company,
The Task Scheduler problem asks us to determine the minimum number of CPU intervals required to complete a list of tasks with a cooling constraint. Each task is represented by an uppercase letter A-Z. The CPU can execute one task per interval or remain idle.
We are asked to construct a convex polygon with vertices that satisfies three conditions. First, all vertices must lie on lattice points, meaning each coordinate is an integer. Second, all sides must have distinct lengths.
The problem describes an ant moving along a one-dimensional infinite line, starting at a boundary point, which we can co
The problem asks us to find the length of the longest turbulent subarray inside a given integer array arr. A subarray is considered turbulent if the relationship between every adjacent pair of numbers alternates between greater than () and less than (<).
The problem gives us an array of integers called nums, where each integer represents a possible side length. Our goal is to select exactly three lengths that can form a valid triangle with a non-zero area, and among all valid triangles, return the maximum possible perimeter.
The problem is asking us to find a "fixed point" in a sorted array of distinct integers. A fixed point is an index i such that the value at that index equals the index itself, i.e., arr[i] == i.
This problem asks us to implement a compressed string iterator. We are given a string where each character is immediately followed by a number representing how many times that character appears consecutively in the uncompressed version. For example, "a3b2" represents "aaabb".
This problem asks us to compute a complete league table from two database tables, Teams and Matches. The Teams table contains the identity of each team in the league. Each row represents one team and includes a unique teamid and the corresponding teamname.
We are given two points in the plane, the ship's starting position and destination, together with a convex polygon representing an island. Moving through the sea costs 1 per unit distance. Moving through the interior of the island costs 2 per unit distance.
The problem describes a "strange printer" that can print sequences of the same character in one turn. The printer can overwrite any existing characters in the string.
We have a rectangular grid with n columns and m rows. Two lasers point at two different cells. Both lasers always move together, meaning their relative offset never changes. If one laser moves by (dx, dy), the other must move by exactly the same vector.
The problem asks us to reconstruct digits from a jumbled string of English letters representing numbers from 0 to 9.
This problem asks us to find the shortest path from a robot's unknown starting position to a hidden target inside a grid. The major challenge is that the grid itself is not directly accessible.
This problem asks us to reroot a binary tree at a given leaf node. Normally, a binary tree has a single root, and every node points downward to its children. In this problem, each node also contains a parent pointer, which allows traversal upward toward the root.
The picture in the statement describes a recursive triangular arrangement of paths and blocked regions. The black segments form a planar graph, and the gray triangles represent forbidden forest areas.
The problem asks us to count the number of contiguous subarrays in a binary array nums whose sum equals a given integer goal. A binary array only contains 0s and 1s.
The problem asks us to count the number of substrings in a string s such that every unique character in the substring occurs exactly count times. A substring is a contiguous segment of the string, so we are only considering consecutive characters.
The problem gives us two integers, n and start. We must construct an array named nums of length n, where each element is
The problem gives us a binary matrix called grid, where each cell contains either 0 or 1. A value of 1 represents land, and a value of 0 represents water. An island is formed by connecting adjacent land cells in the four cardinal directions: up, down, left, and right.
This problem asks us to sort n items while satisfying two different kinds of constraints at the same time. The first constraint comes from dependencies between items. If item a appears in beforeItems[b], then item a must appear before item b in the final ordering.
We are asked to process a sequence of queries, each defined by two integers, x and y. For each query, we need to count how many positive divisors of x do not divide any of the y numbers immediately preceding x in the sequence, that is, the numbers x-y, x-y+1, ..., x-1.
The task is to print a given sequence of integers using a limited number of variables and two operations: assigning a variable to an integer, and printing a variable. Each assignment carries a cost equal to the number of set bits in the assigned number, while printing is free.