brain
tamnd's digital brain — notes, problems, research
43815 notes
The problem presents an m x n matrix grid of positive integers and asks us to simulate a repeated deletion process on it. In each operation, for every row in the matrix, we remove the greatest element.
The problem is asking us to determine the maximum number of minutes n computers can run simultaneously using a given set of batteries. Each battery has a fixed amount of energy in minutes, and you can initially assign at most one battery per computer.
Polycarpus needs to organize daily profit reports into folders, where each folder contains consecutive days. The key restriction is that a folder cannot contain three or more days with negative profit, because the boss cannot tolerate more than two loss days per folder.
The problem is asking us to optimally pair students with mentors such that the sum of their compatibility scores is maximized. Each student and each mentor has answered n yes/no questions represented by 0s and 1s.
The problem asks us to analyze customer purchasing behavior using two relational tables: Transactions and Products. The Transactions table contains every purchase made by customers, including the transaction ID, customer ID, product ID, transaction date, and amount spent.
This is a Type A, “Find all X” problem. A complete solution must do two things: First, it must show that every listed family of solutions actually satisfies the system. Second, it must prove that no other solutions exist. The proposed proof does both parts.
We are given a single positive integer and must print its representation in base 2. In other words, we want to express the number as powers of two and output the corresponding sequence of bits.
We are given a permutation of integers from 1 to n and a list of queries asking for the positions of specific elements. The task is to compare two linear search strategies.
The problem gives us an integer n and an array sums of length 2^n, which contains every possible subset sum of an unknown array of length n.
The problem presents a rectangular piece of wood of size m x n and a list of specific prices for certain subrectangles. Each entry in the prices array, [hi, wi, pricei], indicates that a piece of wood of height hi and width wi can be sold for pricei dollars.
We are given a decimal number as a string. We may independently permute its digits twice, producing two new numbers that contain exactly the same multiset of digits as the original number. Leading zeroes are allowed after permutation.
We want to count strings of length n built from an alphabet of size m, under one strong restriction: every substring of length k must be a palindrome.
In this problem, we have a regular polygon with n vertices, and each vertex initially contains exactly one monkey. Every monkey must move simultaneously to one of its two neighboring vertices.
The problem asks us to find a sequence of indices from word1 such that the characters at those indices, when concatenated in order, form a string that is almost equal to word2.
The problem asks us to process a sequence of removal queries on an array nums, with an optional initial operation where we can replace nums with any subsequence of itself to optimize query processing. Each query specifies a threshold value.
The problem asks us to count the number of distinct quadruplets (a, b, c, d) in a given array nums such that the sum of the first three elements equals the fourth, i.e., nums[a] + nums[b] + nums[c] == nums[d], and the indices satisfy a < b < c < d.
The problem asks us to divide a given array nums into k contiguous subarrays in a very specific way. Each subarray has a cost defined as its first element. The objective is to minimize the total cost, which is the sum of the first elements of all k subarrays.
This problem provides a database table named usercontent with two columns: | Column | Description | | --- | --- | | contentid | Unique identifier for each row | | contenttext | A text string containing words and spaces | The task is to produce a result table that contains: 1.
This problem is asking us to simulate a progressive tax system. We are given a list of tax brackets where each bracket specifies an upper bound of income and a tax percentage.
This problem asks us to count the number of paths in a 2D integer matrix from the top-left corner (0, 0) to the bottom-right corner (m - 1, n - 1) such that the sum of the values along the path is divisible by a given integer k.
The problem gives us a set of unique points on a 2D plane. We need to determine the largest possible axis-aligned rectangle that can be formed using exactly four of those points as its corners.
This problem asks us to compute the minimum total cost required to move from index 0 to index n - 1 in an array. The movement rules are unusual because whether a jump is valid depends not only on the values at the start and destination indices, but also on every element in…
In this problem, we are given a string s containing only lowercase English letters and an integer k. We need to find the length of the longest subsequence such that the difference between every pair of adjacent characters in that subsequence is at most k.
We are asked to determine whether one polygon is completely contained inside another. Polygon A is strictly convex, meaning all internal angles are less than 180 degrees and no three consecutive points are collinear.
The problem gives a queue of n people standing from left to right, where each person has a distinct height. For each person i, we need to determine how many people to their right they can see.
The problem asks us to transform a given string word into a k-special string using the minimum number of deletions. A string is considered k-special if, for every pair of characters in the string, the difference in their frequencies does not exceed k.
The problem requires us to detect the first occurrence of a binary pattern within a theoretically infinite stream of bits. The stream is accessed sequentially using the next() method, which returns one bit at a time.
The problem gives us an integer array nums of length n. We must create and return a new array called answer of length n - 1.
Polycarpus is running a simple monitoring routine for two servers, which we can call server a and server b. Each "ping" command sends exactly ten packets to one of the servers.
This problem asks us to merge two arrays of JSON objects based on a shared id field. Every object in both arrays contains a unique integer id, and our goal is to produce a single merged array where objects with the same id are combined together.
The problem asks us to determine whether we can select two or more elements from a given array of positive integers such that their bitwise OR produces a number whose binary representation ends with at least one zero.
The problem gives us an n x n matrix called grid. Every value in the matrix should normally contain all integers from 1 to n² exactly once. However, there is one mistake in the matrix: - One number appears twice. - One number is completely missing.
The input consists of a 2D array dimensions, where each element represents a rectangle. For a rectangle dimensions[i], the value dimensions[i][0] is its length and dimensions[i][1] is its width.
This problem asks us to take multiple very small binary search trees (BSTs), each with at most three nodes, and attempt to merge them into a single valid BST. Each tree is represented by its root node in the array trees.
We are given a circular arrangement of cows, each cow facing exactly one of its two neighbors. Represent the circle as a binary string where each character describes direction: one symbol means “point to clockwise neighbor” and the other means “point to counterclockwise…
The problem asks us to determine how many lattice points lie inside at least one of a set of circles on a 2D grid. Each circle is represented by a triplet [xi, yi, ri], where (xi, yi) is the circle's center and ri is its radius.
The input describes a tree of cities. Since there is exactly one simple path between every pair of cities, the road network forms a connected acyclic graph. Then we are given several pairs of cities.
This problem asks us to find the longest contiguous subarray that follows a very specific alternating pattern. Given an integer array nums, we need to identify subarrays where: 1. The subarray length is at least 2. 2.
The problem is asking us to construct an array nums3 of length n from two given arrays nums1 and nums2 of the same length. For each index i, we can choose either nums1[i] or nums2[i] as the value for nums3[i].
This problem gives us two arrays, basket1 and basket2, where each element represents the cost of a fruit in a basket. Both baskets contain exactly n fruits.
The problem gives us an integer array nums and an integer k. We are allowed to repeatedly choose any contiguous subarray of length k and decrease every element inside that subarray by 1.
The problem asks us to find all pairs of indices (i, j) in an array hours such that i < j and the sum of hours[i] + hours[j] is an exact multiple of 24, which is considered a "complete day.
That is a long, structured reference document with multiple required sections, detailed prose, two full implementations, worked examples, test cases, and edge-case analysis. To keep quality high and avoid truncation, I will provide it in a complete guide format.
We have a matrix of integers and three kinds of operations applied to it repeatedly. One operation swaps two rows. Another swaps two columns. The third asks for the value currently visible at a specific row and column.
The problem gives us a binary string s, where each character is either '0' or '1'. We start at index 0, and the problem guarantees that s[0] == '0', meaning the starting position is always valid.
The problem describes a two-player turn-based game between Alice and Bob with a row of stones, each having an integer value.
This problem gives us an undirected tree with n nodes and a list of directed parent-child guesses. Each guess claims that one node is the parent of another node when the tree is rooted in some way. The important detail is that the tree itself is undirected.
The problem asks us to process an Orders table where each row contains a minute and the number of orders received during that specific minute. We are tasked with calculating the total number of orders in intervals of six consecutive minutes.
The problem asks us to take an integer array nums and sort its elements based on their indices in two separate ways: the elements at even indices should be sorted in non-decreasing order, and the elements at odd indices should be sorted in non-increasing order.
The problem asks us to count how many substrings of a given string are considered "complete". A substring is complete if it satisfies two conditions simultaneously: 1. Every distinct character in the substring appears exactly k times. 2.
The problem gives us two strings, s1 and s2, each containing exactly four lowercase English letters. We are allowed to repeatedly perform a very specific swap operation on either string.
We have n cubes. Every cube has a color and a size. We want to build a tower using cubes from exactly two distinct colors, and adjacent cubes in the tower must always have different colors. There are no restrictions on cube sizes or ordering.
The problem asks us to find the kth distinct string in an array of strings. A string is considered distinct if it appears exactly once in the entire array. The important detail is that the order matters. We are not sorting the strings or rearranging them in any way.
The problem gives us an array nums and an integer target. We must find a subsequence whose elements add up exactly to target, while maximizing the number of elements included in that subsequence.
The problem asks us to determine if two events on the same day overlap in time. Each event is given as a pair of strings in HH:MM format representing the start and end times. The output should be a boolean: true if there is any overlap between the two events, and false otherwise.
This problem asks us to partition an array nums into exactly m contiguous subarrays such that the bitwise AND of elements in the i-th subarray equals andValues[i].
We have an array of non-negative integers. In one move, we pick an index i with a[i] 0, decrease a[i] by 1, and increase some position j by 1, where j - i must be even and j = i. The parity restriction is the core of the problem.
In this problem, we are given several gardens, where flowers[i] represents how many flowers are already planted in the i-th garden. We are also given a limited number of additional flowers, newFlowers, that we may distribute among the gardens.
We are given an array nums containing positive integers. We need to count how many pairs of indices (i, j) with i < j satisfy a special condition called almost equal.
The problem gives us a 0-indexed array of positive integers and asks us to repeatedly perform a specific operation to reduce the array's length as much as possible.
We are given a string containing lowercase letters, spaces, and a limited set of punctuation marks: comma, dot, exclamation mark, and question mark.
The problem asks us to find the shortest subarray within a given array nums such that the bitwise OR of all elements in that subarray is at least k. A subarray is any contiguous sequence of elements in nums.
The problem provides a database table Logins that records user login events, with columns userid and timestamp. Each combination of (userid, timestamp) is unique, ensuring that every row corresponds to a distinct login.
The problem asks us to process a DataFrame representing customers and remove rows that have duplicate email addresses. Specifically, if multiple rows share the same email value, only the first occurrence should be kept, and all subsequent duplicates should be discarded.
This problem gives us a 2D grid representing a shop layout. Every cell in the grid has one of three meanings: - 0 means the cell is blocked by a wall and cannot be traversed. - 1 means the cell is empty space and can be walked through.
The problem presents a scenario where we have multiple piles of gifts, represented as an integer array gifts, with each element indicating the number of gifts in that pile.
This problem asks us to calculate the percentage of immediate food delivery orders for each unique orderdate. The Delivery table contains one row per order. Each row includes: - deliveryid: A unique identifier for the delivery. - customerid: The customer who placed the order.
This problem asks us to count the number of distinct ways to move from startPos to endPos on an infinite number line using exactly k steps. At each step, we may move either one position to the left (-1) or one position to the right (+1).
We are asked to compute the expected number of shelves that have no untasted honey pots after a series of actions. Each shelf starts with some number of honey pots. Winnie moves a small number of pots from one shelf to another, tasting them in the process.
This problem asks us to find a path in a matrix whose product contains the maximum possible number of trailing zeros. A trailing zero in a number is created by a factor of 10, and every factor of 10 comes from one factor of 2 paired with one factor of 5.
We have an array of friend attractiveness values. Every unordered pair of distinct friends produces one possible picture, and the value of that picture is the xor of the two attractiveness values.
The problem asks us to find the number of pairs of nodes in an undirected graph that cannot reach each other via any path. You are given an integer n representing the total number of nodes labeled from 0 to n - 1 and a list of edges representing connections between nodes.
The problem requires us to partition an array of positive integers nums into two ordered groups such that the sum of elements in each group is at least k. A partition is considered great if this condition is satisfied.
The problem gives us an array of strings called words and a list of range queries called queries. For each query [li, ri], we must determine how many strings in words between indices li and ri, inclusive, both start and end with a vowel.
We are given a fixed string consisting of lowercase letters, and many independent queries. Each query specifies a contiguous segment of this string, and for that segment we must count how many substrings are palindromes.
The problem provides a 2D grid representing a map of land and water cells. Each cell can either be land (value 0) or water containing a positive number of fish.
We are given an array of length (2·n - 1). Yaroslav can perform an operation any number of times where he selects exactly n elements and multiplies each by -1. Our task is to determine the maximum sum achievable by applying this operation optimally.
This problem asks us to reshape a dataset from a wide format to a long format, also known as “melting” in data analysis. In the input DataFrame, each row represents a product, and each column beyond the first represents quarterly sales (quarter1 to quarter4).
This problem asks us to determine whether each passenger's ticket is confirmed or placed on the waitlist, based on the booking order and the capacity of the flight they booked.
The problem provides a database table named transactions, where each row represents a transaction with three fields: - transactionid, a unique identifier - amount, the transaction amount - transactiondate, the date on which the transaction occurred For every distinct…
We know the second bag contains y potatoes. The first bag originally contained some positive number x, but that value was lost. The only remaining information is that the total number of potatoes, x + y, was divisible by k and did not exceed n.
We have n ice sculptures placed evenly on a circle. Each sculpture has a value, which may be positive or negative. We may remove some sculptures, but the remaining ones must still form a regular polygon.
We are given an undirected tree with n nodes. Every node has a price value. Since the graph is a tree, there is exactly one simple path between any two nodes. The problem allows us to choose any node as the root of the tree.
We are asked to analyze a two-player game on a rectangular grid where each cell may contain a toy soldier from Shrek (green) or Donkey (red), or be empty. The grid has dimensions n × m, and on each row there are at most two soldiers.
The problem gives us a zero-based permutation array called nums. A permutation means that every integer from 0 to n - 1 appears exactly once, where n is the length of the array.
This problem asks us to transform a given string into a palindrome using the minimum number of adjacent swaps. A palindrome is a string that reads the same forward and backward. For example, "abba" and "racecar" are palindromes.
The problem asks us to count the number of pairs of non-empty disjoint subsequences from a given array nums such that the GCD of the elements in each subsequence of the pair is equal.
The problem gives us an integer n, representing a conceptual array nums of length n, indexed from 0 to n - 1. We are also given a list of inclusive ranges, where each range marks positions in the array as covered.
The problem gives us a binary matrix grid with m rows and n columns. Every cell contains either 0 or 1. We must construct another matrix called diff, where each position diff[i][j] depends on how many ones and zeros appear in row i and column j.
The problem asks for a function that returns the number of arguments passed to it. Essentially, we need to measure the length of the input in a dynamic, variadic sense. The input is presented as a JSON array in the examples, representing all the arguments passed to the function.
This problem asks us to extend JavaScript's built in Date object by adding a new method called nextDay(). Once implemented, any valid Date instance should be able to call this method and receive a string representing the next calendar day in the format YYYY-MM-DD.
We are asked to construct three permutations $a$, $b$, and $c$ of length $n$ such that for every index $i$ the sum of $a[i]$ and $b[i]$ modulo $n$ equals $c[i]$ modulo $n$.
We are working on a very narrow grid: only two rows, but a large number of columns. Each cell in this 2 by n strip is either free or blocked.
The problem gives us the root of a binary tree and asks us to replace every node’s value with the sum of all of its cousins’ values.
The problem asks us to count how many distinct anagram sentences can be formed from a given string s. The input string contains one or more words separated by single spaces. An anagram sentence must preserve the structure of the original sentence.
In this problem, we are given a 2D binary matrix called room. Each cell represents a position in the room: - 0 means the space is empty and can be cleaned. - 1 means the space contains an object and cannot be entered.
The problem is asking us to maximize the number of consecutive integers we can select from an array after we are allowed to increase any element by at most 1.
In this problem, we are given a row of plants where each plant requires a certain amount of water. Two people, Alice and Bob, water the plants simultaneously from opposite ends of the array. Alice starts from the left side at index 0 and moves toward the right.
The problem is asking us to determine the minimum total cost to paint n walls using two painters with different constraints. We are given two arrays: cost and time, both of size n.
Mashmokh wants to pick a sequence of n distinct integers so that his boss, Bimokh, gains exactly k points in a game.