brain
tamnd's digital brain — notes, problems, research
42624 notes
The problem asks us to count all substrings in a given string s that start and end with the same character. A substring is a contiguous sequence of characters, so the order and adjacency of characters matter.
The problem gives us a compressed string where every character is immediately followed by its frequency. For example, the string "a3b2" represents the original expanded string "aaabb". However, the input compression is not guaranteed to be optimal.
The problem gives us an integer array nums and asks for the length of the longest contiguous subarray whose first element is strictly greater than its last element. A subarray is any contiguous segment of the array. For a subarray nums[i...
This problem asks us to implement a concurrency limiter for asynchronous operations. We are given an array called functions, where each element is itself a function. When one of these functions is called, it returns a Promise.
We are given two strings, word1 and word2. We need to count how many substrings of word1 are considered valid. A substring is valid if its characters can be rearranged so that word2 becomes a prefix of the rearranged string.
We are given a binary string s, containing only '0' and '1'. We must count how many substrings satisfy a special condition called "dominant ones".
We are given n cities labeled from 0 to n - 1. Initially, the graph forms a simple directed chain: - 0 - 1 - 1 - 2 - 2 - 3 - ...
We are asked to count rhombi inside a rectangle of width w and height h, where each rhombus has its vertices on integer coordinates and diagonals aligned with the axes. Each rhombus must have positive area and be fully contained in the rectangle.
We are given an array nums, where each element represents the value assigned to a node in a graph. The graph contains exactly n nodes, one node for each array element.
The forum keeps a list of threads ordered by the time of their latest message. Whenever someone posts in a thread, that thread immediately moves to the front of the list. No other reordering happens. Initially the threads are ordered as 1, 2, 3, ..., n.
Greg performs exercises in a fixed repeating order. The first exercise trains the chest, the second trains the biceps, the third trains the back, then the pattern repeats again: chest, biceps, back, and so on.
The problem asks us to identify words in the queries list that can be transformed into a word in the dictionary list with at most two character edits. Each edit consists of changing a single character to another lowercase English letter.
The problem requires categorizing a box based on its dimensions and mass according to given criteria. We are given four integers: length, width, height, and mass. The output is a string that represents the category of the box: "Bulky", "Heavy", "Both", or "Neither".
The problem asks us to process an array of lowercase strings words and a single lowercase character x, and return all indices of the words that contain this character. In simpler terms, for each string in the array, we must check whether x appears anywhere in that string.
The problem asks us to determine how many possible sequences of integers exist that match a given array of differences between consecutive elements, while staying within a specified inclusive range.
We are asked to construct a complete record of matches between n teams, where every match has a winner and a loser, and no pair of teams plays more than once.
The problem asks us to construct a polynomial equation from a database table called Terms. Each row in the table represents a single term in the equation, where power is the exponent of X and factor is the coefficient.
The problem asks us to identify the longest square streak in an array of integers nums. A square streak is a subsequence of at least length 2 where, after sorting, every element is the square of the previous element. In other words, if the sorted subsequence is [x1, x2, ...
The problem gives us a square matrix nums of size n x n. We need to examine the values that appear on the two diagonals of the matrix and return the largest value among them that is prime.
This problem gives us two arrays, nums1 and nums2, both of the same length n, along with a list of queries. Each query modifies one of the arrays or asks for information about them.
The problem asks us to find the largest possible even sum of a subsequence of length k from a given integer array nums. A subsequence is a sequence that can be obtained by deleting some elements from the array without changing the relative order of the remaining elements.
The problem gives us a sorted array prizePositions, where each value represents the position of a prize on the X-axis. Multiple prizes may exist at the same position. We are also given an integer k. We may choose exactly two segments on the number line.
The problem is asking us to simulate a painting process on a 2D matrix. We are given a 1D array arr of integers and an m x n matrix mat, both containing all integers from 1 to m n exactly once.
The problem asks us to compute the maximum Hamming distance for each element in an array of integers. The Hamming distance between two integers is defined as the number of positions where their binary representations differ.
The problem asks us to find the smallest integer strictly greater than n such that the number is numerically balanced. A number is numerically balanced when every digit that appears in the number appears exactly as many times as its value.
The problem asks us to manipulate an array of integers, nums, so that its prefix sums are never negative. A prefix sum at index i is simply the sum of all elements from the start of the array up to i.
The problem asks us to construct a binary tree from a list of relationships, where each relationship is given as [parent, child, isLeft].
The problem is asking us to count the number of ways to paint an m x n grid using three colors: red, green, and blue, with the constraint that no two adjacent cells can have the same color. Adjacent cells include both vertically and horizontally neighboring cells.
The problem asks us to identify all valid chemical bonds that can form between elements in a given table. The Elements table contains three columns: symbol, type, and electrons. The type column is an enumeration of 'Metal', 'Nonmetal', and 'Noble'.
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.
We are given an integer array nums. We may repeatedly choose any element and replace it with any positive integer x. Replacing a value nums[i] with x costs |nums[i] - x|.
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 gives us a binary string s and a list of queries. Each query contains two integers, first and second. For every query, we need to find a substring of s whose decimal value satisfies: where ⊕ represents the bitwise XOR operation.
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 asks us to take an array of integers, nums, and repeatedly form pairs of equal numbers until no more pairs can be formed. Each operation removes exactly two identical numbers from the array, and we continue doing this until it is no longer possible.
We are asked to maximize the total number of flamingos that can be observed from a row of binoculars on the x-axis. Each binocular sits at position (i,0) and can be aimed in any direction.
We are given a circular array called colors, where each element is either 0 or 1. These represent red and blue tiles arranged in a ring, which means index 0 and index n - 1 are adjacent.
The problem gives us a ladder represented by a strictly increasing array called rungs. Each value in the array represents the height of a rung above the floor. You begin standing on the floor at height 0, and your goal is to reach the final rung.
The problem asks us to analyze a maze represented as an undirected graph of n rooms connected by corridors. Each corridor allows travel in both directions, and the input corridors lists all such connections.
This is a SQL database problem involving two tables: | productid | price | | --- | --- | | Unique product identifier | Unit price of the product | | invoiceid | productid | quantity | | --- | --- | --- | | Invoice identifier | Product purchased | Number of units purchased |…
We are asked to determine whether a ticket number is lucky. A lucky ticket number satisfies two conditions simultaneously. First, every digit of the number must be either 4 or 7.
The problem provides a singly linked list where the nodes are sorted in non-decreasing order by their absolute values, rather than their actual values. The task is to rearrange this list so that the nodes are sorted in non-decreasing order according to their actual values.
The problem asks us to take a four-digit integer num and split its digits into two new integers such that the sum of these two integers is minimized. We are allowed to use all digits exactly once, and the new integers can have leading zeros.
This problem asks us to compute a 3-day rolling average of daily step counts for each user. The input is a table named Steps, where each row contains: - userid, identifying a user. - stepscount, the number of steps taken on a particular day.
Each employee follows a rigid repeating schedule. Once hired on day x, the employee works for n consecutive days, then rests for m consecutive days, then repeats forever. So the cycle length is n + m, and inside each cycle the employee is active for the first n days.
In this problem, we are given the starting mass of a planet and a list of asteroid masses. The planet can collide with the asteroids in any order we choose.
The problem gives us an array called milestones, where each value represents how many milestones belong to a particular project. Every week, we must complete exactly one milestone from one project.
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.
We are given two permutations, one of length n and another of length m (n ≤ m). A permutation is a sequence containing all numbers from 1 to its length exactly once.
The problem asks us to count all subarrays of a given array nums such that if we remove the subarray, the remaining array becomes strictly increasing. A strictly increasing array is one where each element is less than the next element.
The problem requires us to find the number of arithmetic triplets in a strictly increasing array of integers. An arithmetic triplet (i, j, k) satisfies the conditions i < j < k, nums[j] - nums[i] == diff, and nums[k] - nums[j] == diff.
We are given an undirected tree with n nodes labeled from 0 to n - 1. The tree is rooted at node 0, which means every node except the root has exactly one parent, and each node may have zero or more children. The task is to count how many nodes are considered "good".
In this problem, we are given a list of stock prices over different days. Each element in stockPrices is a pair: This represents a point on a 2D graph where: - The X-axis is the day - The Y-axis is the stock price on that day The line chart is formed by connecting consecutive…
The problem gives us a weighted tree representing servers connected by edges with weights. The servers are numbered from 0 to n-1. Each edge has a weight representing distance or cost.
This problem asks us to simulate the process of entering a cooking time into a microwave while minimizing the total finger movement and button pressing cost. The microwave accepts at most four digits.
The problem describes a bank floor plan as a binary matrix, represented by an array of strings. Each row corresponds to one row in the bank, and each character in the string represents a cell.
This problem asks us to divide a message into multiple parts while respecting a strict maximum length constraint for every part.
The problem requires transforming a given integer array nums into an alternating array with the minimum number of operations.
The problem asks us to construct a string from the characters of a given string s under a specific constraint: no character can appear more than repeatLimit times consecutively.
This problem asks us to find the airport(s) with the most traffic using a table of flights. Each row of the Flights table represents a direct connection from departureairport to arrivalairport along with the number of flights flightscount for that route.
We have a collection of cards, each with a front color and a back color. Initially, all cards lie with the front side up. The goal is to make at least half of the cards show the same color on the upper side.
This problem provides a Pandas DataFrame named animals with four columns: | Column | Type | | --- | --- | | name | object | | species | object | | age | int | | weight | int | The task is to return a new DataFrame containing only the names of animals whose weight is strictly…
We have several jobs, each with a start time, a duration, and a profit. A machine that starts a job stays occupied for the entire interval from s through s + t - 1. At most k jobs may run simultaneously because we only own k machines. The goal is not to schedule all jobs.
We are given a string of lowercase English letters and a sequence of queries. Each query specifies a substring, and for each substring, we are asked to rearrange its letters into a palindrome if possible.
The problem asks us to partition a list of student grades into multiple ordered groups under two strict conditions. First, the total sum of grades in the i-th group must be less than that of the (i+1)-th group.
The problem is asking us to analyze call records from a Calls table and determine the peak calling hour for each city. Each row in the table contains a callerid, recipientid, a timestamp (calltime), and the city where the call originated.
The problem gives an integer array cards, where each number represents the value written on a card. Two cards are considered matching if they contain the same value.
The problem gives us a binary string s, which means the string contains only the characters '0' and '1'. We need to determine whether the longest contiguous sequence of 1s is strictly longer than the longest contiguous sequence of 0s.
This problem asks us to implement a function that returns an infinite-method object. The defining property of this object is that any method name can be accessed and called, and when invoked, it should return the exact name of the method.
This problem asks us to maximize the number of indices in an array that can be "marked" using a specific operation. You are given an integer array nums and can repeatedly pick two different unmarked indices i and j such that 2 nums[i] <= nums[j].
We have two collections of objects. Markers are described by (color, diameter) and caps are also described by (color, diameter). A cap can be attached to a marker only if the diameters are equal.
The problem asks us to count subarrays in an integer array nums where the maximum element of the subarray occurs at least k times.
The problem asks us to compute a special value called the x-sum for every contiguous subarray of length k. For each window of size k, we first count how many times each number appears. After that, we only keep the contributions of the top x most frequent distinct values.
We are given a very large range of possible values for a parameter m, and for each such value a deterministic procedure produces a matrix filled using bitwise XOR rules. The matrix has size (m + 1) by (m + 1), and the filling follows a fixed recursive or constructive pattern.
Each cross is defined by two axis-aligned rectangles centered at the same cell (x0, y0). The first rectangle extends a cells vertically and b cells horizontally from the center, so its size is: $(2a+1)(2b+1)$ The second rectangle is defined similarly using c and d.
We are given a string s representing Alice’s moves across n rounds of a game. Each character corresponds to one creature: - 'F' = Fire Dragon - 'W' = Water Serpent - 'E' = Earth Golem In every round, Alice and Bob each choose one creature simultaneously.
We are asked to transport a group of schoolchildren through a sequence of regions along a single road. Each region has a fixed outdoor temperature and a maximum tolerable bus temperature. Every child inside a bus above that tolerable temperature triggers a monetary penalty.
We are given an array nums and an integer k. We must choose a subsequence of exactly 2 k elements while preserving the original order of the array. After selecting the subsequence, we split it into two equal halves: - The first k selected elements form the left group.
The problem asks us to compute the absolute difference between the sum of elements to the left and the sum of elements to the right for each element in a given array nums. In other words, for every index i, we want to know how different the sums on either side of that index are.
The problem gives us an integer array nums and an integer k. We must count how many contiguous subarrays have a least common multiple, LCM, exactly equal to k. A subarray is any continuous segment of the array. For every possible subarray, we compute the LCM of all its elements.
The problem gives us a binary string s consisting only of characters '0' and '1'. Our goal is to make every character in the string equal, meaning the final string must become either all '0' characters or all '1' characters. We are allowed to perform two types of operations: 1.
This problem asks us to compute how much rainwater can be trapped between vertical bars after rainfall. The bars are represented in a database table named Heights, where each row contains an id and a height.
The problem asks us to determine the minimum number of sequential queries required to transform an array nums into a Zero Array, where all elements are zero. Each query specifies a subarray [li, ri] and a value vali.
We are maintaining a mutable array of integers where two types of operations are performed repeatedly: range sum queries and range updates where every element in a subarray is XORed with a fixed value.
We are given a multiset of digits and asked to construct the largest integer from some or all of them such that the resulting number is divisible by 2, 3, and 5 simultaneously.
This problem is essentially asking how many distinct ways we can select questions from multiple types to reach exactly a target score. Each type of question has a fixed number of questions (counti) and a fixed number of points per question (marksi).
This problem asks us to determine if there exists a path in a binary matrix from the top-left corner (0, 0) to the bottom-right corner (m - 1, n - 1) such that the number of 0s visited along the path is equal to the number of 1s.
We are given a company where employees participate in several independent chat groups. Each chat has a fixed membership defined in advance. Over time, a log records messages: each event says that a particular employee posts in a particular chat.
The problem gives us a numeric string s and asks whether it can be split into at least two non-empty substrings such that their integer values form a strictly descending sequence where every adjacent pair differs by exactly 1.
The problem asks us to find the maximum number of points that can be contained in a square centered at the origin (0, 0) such that no two points inside the square share the same tag. The square's edges are parallel to the axes, and points on the edges are considered inside.
The problem asks us to compute the beauty of every contiguous subarray of size k within a given integer array nums. The beauty of a subarray is defined as the xth smallest negative number in that subarray. If a subarray contains fewer than x negative numbers, the beauty is 0.
We are given a chronological log of private messages between users in a social network. Each record contains the sender, the receiver, and the timestamp of the message. Two users become friends if one of them replies to the other's message quickly enough.
The problem asks us to examine every possible non-empty subset of the given array nums and compute the bitwise OR value of each subset. Among all these OR values, we need to determine the maximum possible value, then count how many different subsets produce that maximum.
We are asked to simulate a three-dimensional billiard-like scenario where a ball travels inside a rectangular corridor with perfectly reflecting walls, floor, and ceiling.
We are asked to count how many ways a simple polygon with $n$ vertices can be triangulated. Triangulation here means splitting the polygon into triangles that exactly cover the polygon without overlap and without introducing new points.
The problem gives us an m x n grid where each cell contains a small integer value. We start at the top left corner (0, 0) and must reach the bottom right corner (m - 1, n - 1) by moving only right or down. Along every path, we compute the XOR of all visited cell values.
We are given an array of integers and must count how many subsequences of length exactly k satisfy a special restriction on lucky numbers. A number is lucky if every decimal digit is either 4 or 7. Examples are 4, 47, and 744. Numbers like 5, 17, and 467 are not lucky.
We have several mugs that already contain different amounts of Ber-Cola. There is also some drink left in the bottle. We must pour the entire remaining amount into the mugs so that every mug ends up with exactly the same volume. If the initial amounts are a1, a2, ...
The problem gives us two strings, start and target, both having the same length. Each position in the strings contains one of three characters: - 'L', representing a piece that can only move left - 'R', representing a piece that can only move right - '', representing an empty…
The problem describes a simplified scoring system for a bowling game between two players. Each player has an array representing the number of pins hit in each turn, and there are exactly n turns.