brain
tamnd's digital brain — notes, problems, research
43815 notes
This problem asks us to filter a string based on character frequency while preserving the original order of characters. We are given a string s consisting only of lowercase English letters and an integer k.
The problem asks us to find the least frequent digit in the decimal representation of a given integer n. In other words, we need to count how many times each digit from 0 to 9 appears in the number, and then return the smallest digit that occurs the fewest times.
The problem asks us to calculate the greatest common divisor (GCD) of two specific sums derived from an integer input n. The first sum, sumOdd, is the sum of the first n positive odd numbers, and the second sum, sumEven, is the sum of the first n positive even numbers.
This problem is a SQL aggregation and filtering task. We are given a table named customertransactions that contains every transaction performed by customers. Each row represents either a purchase or a refund.
The problem asks us to find the minimum cost to travel from the top-left corner (0, 0) of a 2D grid to the bottom-right corner (m - 1, n - 1). Each cell contains a non-negative integer representing its cost. There are two ways to move: 1.
We are given an array nums and a list of queries. Each query has the form: For a query, we start at index li and repeatedly jump forward by ki until we pass ri. Every visited position is multiplied by vi, and the result is taken modulo 10^9 + 7.
We are given an integer array nums and a list of queries. Each query has the form: For a query, we start at index li and repeatedly move forward by ki positions until we exceed ri.
This problem asks us to calculate the maximum possible profit from a stock trading strategy with the option to modify it once in a very specific way.
This problem asks us to distribute a set of items, each with a given weight, into two separate bags with fixed capacity limits, in order to maximize the total weight placed across both bags.
The problem gives an n × m grid where each cell is identified by coordinates (r, c). A sensor can be placed on any cell, and its coverage is defined using Chebyshev distance. Specifically, a sensor at (r, c) covers every cell (r2, c2) such that max(|r - r2|, |c - c2|) ≤ k.
This problem asks us to construct a number system under two simultaneous constraints and then perform a “next greater element” query over that constrained set.
We are given an integer array nums, and we must find the maximum possible sum of a contiguous subarray that follows a very specific shape: 1. It first increases strictly. 2. Then decreases strictly. 3. Then increases strictly again. More formally, for a subarray nums[l...
This problem gives us an m x n matrix called grid and three integers: x, y, and k. The values x and y specify the top-left corner of a square submatrix, while k specifies the side length of that square.
We are given an integer array nums and an integer k. A subarray is considered semi-repeating if the number of distinct values that appear more than once inside that subarray is at most k.
The problem asks us to process multiple queries on a given array nums where each query specifies a subarray defined by [li, ri] and a threshold. For each query, we need to find an element in the subarray that appears at least threshold times.
We are given an array weight representing parcels arranged in a line. We must partition some prefix-suffix segments of this array into a collection of non-overlapping contiguous subarrays called shipments.
This problem asks us to count the number of contiguous subarrays of a given array nums such that the bitwise XOR of all elements in the subarray is greater than or equal to a given integer k. The input array nums consists of positive integers, and k is a non-negative integer.
The problem asks us to partition an integer array nums into three subsequences A, B, and C such that every element belongs to exactly one subsequence.
The problem asks us to count the number of unique trapezoids that can be formed from a set of points on a 2D Cartesian plane. Each point is given as a pair of integers representing its x and y coordinates.
This problem asks us to identify stores with an inventory imbalance. Specifically, for each store, we need to compare the quantity of the most expensive product against the quantity of the cheapest product.
We are given a directed acyclic graph (DAG) with n nodes numbered from 0 to n - 1. Each directed edge is represented as: and stored in: We are also given a boolean array online, where: The problem guarantees that node 0 and node n - 1 are always online.
The task asks us to identify students who exhibit a very specific behavioral pattern in their study history, called a Study Spiral Pattern. We are given two relational tables: one describing students and another describing their study sessions over time.
The problem asks us to determine if a given positive integer n is divisible by the sum of two specific quantities derived from its digits: the digit sum and the digit product.
The problem asks us to simulate the construction of a string called result by processing an input string s from left to right. The input string contains lowercase English letters and three special operators: , , and %.
The problem is asking us to count islands in a 2D grid where the sum of the values in each island is divisible by a given integer k.
The problem gives us an integer array nums and asks us to divide its elements into two groups based on their indices. Array A contains all elements whose indices are prime numbers. Array B contains all remaining elements, meaning indices that are not prime.
The problem defines a transformation process over a string s that contains lowercase letters and three special operation characters: '', '', and '%'. We process the string from left to right, maintaining a dynamically changing result string.
We are given an array nums and an integer maxC. A subarray is called stable if the greatest common divisor (HCF/GCD) of all elements in that subarray is at least 2. The stability factor of the entire array is defined as the length of the longest stable subarray.
The problem is asking us to validate a set of coupons based on three criteria: the coupon code must be a non-empty string containing only alphanumeric characters or underscores, the business line must belong to a set of four predefined categories, and the coupon must be active.
This problem asks us to compute the minimum time required to reach the last node in a directed graph where each edge has a time window constraint.
The problem gives an undirected graph of c power stations labeled from 1 to c, connected by bidirectional cables. These connections define connected components, which are referred to as power grids.
This problem asks us to partition an array of integers, nums, into exactly k non-empty contiguous subarrays, and then compute the bitwise XOR of each subarray. The goal is to minimize the maximum XOR among these subarrays.
This problem is a shortest-path optimization over a highly constrained state space where you are repeatedly moving groups of people across a river using a single boat.
We are given a string s and must partition it into segments according to a very specific process. We start at the current position in the string and begin building a segment character by character.
This is a SQL database problem involving pattern matching on strings. We are given a table named Products with two columns: | Column | Description | | --- | --- | | productid | Unique identifier for each product | | name | Product name string | The goal is to return all…
This problem requires computing the minimum total cost to traverse a grid from the top-left corner (0, 0) to the bottom-right corner (m - 1, n - 1) while following a strict alternating movement pattern. Each cell (i, j) has a cost to enter, calculated as (i + 1) (j + 1).
The problem gives us a 1-indexed array numWays, where numWays[i] indicates the number of ways to form a total amount i using an infinite supply of some unknown coin denominations. The goal is to recover the original set of coin denominations.
This problem asks us to determine whether any number in an array appears a prime number of times. In other words, for each unique number in the input array nums, we calculate its frequency-the number of occurrences-and check if that frequency is a prime number.
We are given an integer array nums and an integer k. We must count how many contiguous subarrays satisfy two conditions: 1. The subarray contains at least two prime numbers. 2.
The task is to identify patients who have recovered from COVID based on their testing history. We are given two tables: one containing patient demographic information and another containing COVID test records with timestamps and results.
We are given a weighted tree with n nodes. A tree is an undirected connected graph with exactly n - 1 edges, which guarantees that there is exactly one simple path between any two nodes. Each edge has a positive weight.
We are given n distinct points on a 2D Cartesian plane. Each point is represented as [x, y]. We must choose any three points that form a non-degenerate triangle, meaning the area must be strictly greater than zero.
The problem asks us to transform a given caption string into a valid video tag following a strict sequence of rules. The input is a single string caption consisting only of English letters and spaces. These words must be transformed into a single hashtag-style identifier.
The task asks us to identify employees whose performance has consistently improved over their most recent three performance reviews.
The problem asks us to transform one string, word1, into another string, word2, using the minimum number of operations. Both strings have equal length and consist only of lowercase English letters.
We are given an array nums and an integer k. We want to split the array into one or more contiguous, non-empty segments. Every element must belong to exactly one segment, and the segments must preserve the original order of the array.
The problem presents a set of n computers, each with a unique password complexity represented in an array complexity of length n. The computers are labeled 0 to n - 1, and only computer 0 is initially unlocked.
This problem extends the classic stock trading dynamic programming family by allowing two different kinds of transactions. A normal transaction consists of buying first and selling later. If the stock price rises, the profit is: A short selling transaction reverses the order.
The problem asks us to choose a contiguous subarray from an array of positive integers after performing at most k doubling operations, where each element can be doubled at most once.
This problem asks us to construct the shortest string that contains two given strings, s1 and s2, as substrings. In other words, we are asked to merge s1 and s2 in such a way that no unnecessary characters are added, but both strings appear contiguously somewhere in the…
This problem asks us to identify books in a library system that are both fully unavailable for borrowing and currently have active borrowers who have not returned them yet. We are given two tables.
The problem requires computing a specific statistic for every contiguous k x k submatrix of a given m x n integer matrix grid. For each submatrix, we must find the minimum absolute difference between any two distinct elements.
The problem asks us to transport two logs of lengths n and m using three trucks, where each truck can carry a log of length at most k. If a log is longer than k, it must be cut into smaller pieces.
The problem asks us to find a path that visits every cell of a given m x n grid exactly once while visiting certain numbered cells in a specified order. Specifically, the grid contains integers from 1 to k in exactly one cell each, and the rest of the cells are zeros.
The problem asks us to find the lexicographically smallest string that can be formed by repeatedly removing adjacent pairs of characters in a string s that are consecutive in the alphabet. Consecutive letters can be in either order (e.g.
The problem asks us to repeatedly remove pairs of adjacent characters in a string that are consecutive in the alphabet, considering the alphabet as circular.
We are given an undirected tree with n nodes, rooted at node 1. Every edge will eventually receive a weight of either 1 or 2. For each query [u, v], we only care about the unique path connecting u and v. All edges outside that path are completely irrelevant and should be ignored.
The input arrays represent polynomials in coefficient form. If: then it represents: Similarly: represents: The task is to compute the product polynomial: and return its coefficients.
This is a SQL database problem involving customer purchasing behavior across product categories. We are given two tables: ProductPurchases records which products each user purchased. A user may purchase multiple products, and each purchase has a quantity.
We are given a weighted, undirected tree with n nodes. Because the graph is a tree, there is exactly one simple path between any two nodes.
This problem presents a 2D grid traversal scenario with obstacles and teleportation portals. You are given a matrix of characters representing cells. Empty cells '.
The graph is undirected, connected, and every node has degree at most 2. A connected graph where every node has degree at most 2 can only have one of two shapes: - A simple path, containing exactly n - 1 edges. - A simple cycle, containing exactly n edges.
This problem asks us to determine whether a rectangular grid of positive integers can be split into two parts with exactly the same sum using a single straight cut. The cut can be made in only one of two ways: - A horizontal cut between two adjacent rows.
This problem asks us to select a subset of nodes in a rooted tree such that each selected node triggers a subtree inversion, and inversions interact through ancestor-descendant relationships with a distance constraint.
The problem gives us a string s containing lowercase English letters and an integer k. We are allowed to delete any characters from the string, including multiple occurrences of the same character.
The problem requires us to reduce all elements of a given non-negative integer array nums to zero using the fewest number of operations. Each operation allows selecting a contiguous subarray and setting all occurrences of the minimum non-negative integer in that subarray to zero.
We are given a directed acyclic graph (DAG) with n nodes and weighted directed edges. Each edge is represented as [u, v, w], meaning there is a directed edge from node u to node v with weight w. The goal is to find a path that satisfies two conditions: 1.
This problem describes a set of n houses arranged in a circle. Between adjacent houses, there are two directed road systems: - forward[i] is the distance from house i to (i + 1) % n. - backward[i] is the distance from house i to (i - 1 + n) % n.
The problem requires analyzing a string s composed of lowercase English letters and determining the sum of the maximum frequency of vowels and the maximum frequency of consonants. Vowels are defined as 'a', 'e', 'i', 'o', and 'u'. All other letters are consonants.
This problem presents a road of length l kilometers, segmented by n signs at strictly increasing positions, where the first sign is at the start of the road (position[0] = 0) and the last sign is at the end of the road (position[n-1] = l).
The input describes a collection of unit conversion relationships. Each conversion is given as: source - target with factor f meaning: 1 unit of source = f units of target The important observation is that there are exactly n - 1 conversion edges among n units, and the…
The problem gives us a positive integer n and asks us to find the maximum product that can be formed by multiplying any two digits that appear in the number. The input is a single integer.
We are given an array nums containing up to 13 positive integers and an integer k. We may reorder the numbers in any permutation. After choosing an ordering, we concatenate the decimal representations of the numbers to form a single large integer.
We are given a character matrix and a pattern string. The key observation is that the problem defines two unusual traversal orders: - A horizontal traversal reads the matrix row by row, from left to right. When a row ends, reading continues at the beginning of the next row.
This problem defines an undirected graph implicitly through a sorted array nums. Each index in nums represents a graph node. Two nodes i and j are connected by an edge whenever: We are then given many connectivity queries.
The problem requires computing the maximum possible profit achievable by processing nodes of a Directed Acyclic Graph (DAG) in a valid topological order.
This problem gives us a two dimensional array of strings called responses. Each responses[i] represents all survey responses collected on the ith day. A response is simply a string such as "good", "ok", or "bad".
For each query, two things happen in order. First, we permanently update one element of nums: This modification remains in effect for all future queries. Second, we conceptually remove the prefix nums[0..start-1].
The operation described in the problem may initially look unusual, but it is actually equivalent to choosing a non-empty contiguous subarray. When we remove a prefix and a suffix that do not overlap, the elements left behind form a contiguous segment of the original array.
The problem asks us to transform an integer array nums into a non-decreasing array by performing zero or more operations, where an operation consists of selecting a contiguous subarray and replacing it with its maximum value.
We are given a string s that is guaranteed to already be a palindrome. We may rearrange its characters, but the final rearranged string must also be a palindrome.
We are given a weighted tree with n nodes, rooted at node 1. A tree has exactly one simple path between any pair of nodes. Since the tree is rooted at node 1, every node has a unique path from the root.
We are given an integer array nums, and we must consider every triplet of indices (i, j, k) such that i <= j <= k. For each valid triplet, we compute: where ⊕ denotes the bitwise XOR operation. The goal is not to count triplets.
Before diving into the detailed solution guide, I want to clarify one subtle point: the problem specifies that all subarrays with more than two elements must have a positive sum. This means the smallest subarray we need to consider is of length 3.
The problem asks us to determine the number of unique values that can result from taking the XOR of three elements in a given array nums, where the triplets (i, j, k) must satisfy i <= j <= k.
The problem asks us to take a palindromic string s and return its lexicographically smallest palindromic permutation.
This problem gives us three integers, x, y, and z, representing the positions of three people on a one-dimensional number line. Person 1 starts at position x, Person 2 starts at position y, and Person 3 remains stationary at position z.
The problem gives us an integer array nums and an integer k. We are allowed to repeatedly perform one operation: choose any index i and decrease nums[i] by exactly 1.
We are given an array nums. The operation is highly constrained: 1. Among all adjacent pairs, find the pair with the minimum sum. 2. If multiple adjacent pairs have the same minimum sum, choose the leftmost one. 3. Replace those two elements with their sum.
The problem asks us to find a subsequence of a given integer array nums such that the alternating sum of the subsequence equals a target integer k, while maximizing the product of the numbers in that subsequence without exceeding a given limit.
The problem is asking us to design a Router data structure to manage network packets efficiently under memory constraints. Each packet has three attributes: source, destination, and timestamp. The router has a memory limit, meaning it can store only a fixed number of packets.
We are given an array nums. At any step, we are not free to choose any adjacent pair. Instead, the operation is completely determined by the current state of the array: 1. Find the adjacent pair whose sum is the smallest. 2.
We are given two strings, s and t, and we are allowed to choose: 1. Any substring of s, including the empty string. 2. Any substring of t, including the empty string. The chosen substring from s must come first, and the chosen substring from t must come second.
This is a SQL aggregation problem where we need to analyze user subscription behavior and return statistics only for users who successfully converted from a free trial to a paid subscription. The UserActivity table contains one row per user, per day, per activity type.
The problem asks us to model a 2D array of integers, called properties, as an undirected graph. Each row of the array corresponds to a node in the graph. Two nodes are connected if the number of distinct integers they share is at least k.
The problem gives a binary string s representing sections of a system, where '1' indicates an active section and '0' indicates an inactive section. We are allowed at most one trade to maximize the number of active sections.
The problem presents a binary string s where each character represents an active ('1') or inactive ('0') section. For each query, which specifies a substring of s, we are asked to determine the maximum number of active sections after performing at most one trade operation.
This problem asks us to partition an array nums into contiguous subarrays, where each subarray contributes a weighted cost to the total. The cost for a subarray nums[l..
The problem asks us to compute a special value called the reverse degree of a string. Normally, letters are assigned positions in the alphabet as: - 'a' = 1 - 'b' = 2 - ... - 'z' = 26 However, this problem uses the reversed alphabet order, where: - 'a' = 26 - 'b' = 25 - ...
This problem describes a cargo ship with an n × n deck. Since each cell on the deck can hold exactly one container, the deck has a total capacity of: physical container positions. Every container has the same weight, w. The ship also has a maximum total weight limit, maxWeight.