brain

tamnd's digital brain — notes, problems, research

43815 notes

CF 430B - Balls Game

We are given a row of balls, each colored with one of k colors. No color initially appears three times in a row. Iahub holds a single extra ball of a given color x and can insert it anywhere in the row, including before the first ball or after the last.

codeforcescompetitive-programmingbrute-forcetwo-pointers
CF 242E - XOR on Segment

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.

codeforcescompetitive-programmingbitmasksdata-structures
LeetCode 2113 - Elements in Array After Removing and Replacing Elements

The problem describes an array that continuously goes through a repeating two-phase process. At minute 0, the array is unchanged. Every following minute, the leftmost element is removed until the array becomes empty.

leetcodemediumarray
LeetCode 3148 - Maximum Difference Score in a Grid

The problem gives us an m x n matrix called grid, where every cell contains a positive integer. From any cell (r1, c1), we are allowed to move to another cell (r2, c2) as long as the destination is either strictly below or strictly to the right.

leetcodemediumarraydynamic-programmingmatrix
LeetCode 2065 - Maximum Path Quality of a Graph

We are given an undirected weighted graph where each node has an associated value. A path is considered valid if: 1. It starts at node 0 2. It ends at node 0 3.

leetcodehardarraybacktrackinggraph-theory
LeetCode 3130 - Find All Possible Stable Binary Arrays II

The problem gives us three integers: - zero, the exact number of 0s that must appear in the array - one, the exact number of 1s that must appear in the array - limit, the maximum allowed length of any consecutive block of identical values We must count how many binary arrays…

leetcodeharddynamic-programmingprefix-sum
LeetCode 2597 - The Number of Beautiful Subsets

The problem asks us to count how many non-empty subsets of the array nums are considered "beautiful". A subset is beautiful if there are no two numbers inside the subset whose absolute difference equals k.

leetcodemediumarrayhash-tablemathdynamic-programmingbacktrackingsortingcombinatorics
CF 306C - White, Black and White Again

We are asked to compute the number of ways to distribute a set of good and not-so-good events across a sequence of days divided into three consecutive segments: a white segment, a black segment, and a second white segment.

codeforcescompetitive-programmingcombinatoricsnumber-theory
LeetCode 2636 - Promise Pool

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.

leetcodemedium
LeetCode 3125 - Maximum Number That Makes Result of Bitwise AND Zero

The problem asks us to find the largest integer x such that: - x <= n - The bitwise AND of every integer in the inclusive range [x, n] equals 0 In other words, we want the widest possible suffix ending at n whose cumulative bitwise AND becomes zero, while keeping x as large as…

leetcodemediumstringgreedysorting
LeetCode 3017 - Count the Number of Houses at a Certain Distance II

We are given a graph of n houses arranged in a straight line. Normally, every house i is connected to i + 1, so the graph forms a simple path: 1 - 2 - 3 - ... - n In addition to these standard edges, there is one extra street connecting house x and house y.

leetcodehardgraph-theoryprefix-sum
LeetCode 2646 - Minimize the Total Price of the Trips

The problem gives us an undirected tree with n nodes. Every node has a price associated with it, and we are also given several trips between pairs of nodes. Since the graph is a tree, there is exactly one simple path between any two nodes.

leetcodehardarraydynamic-programmingtreedepth-first-searchgraph-theory
LeetCode 2196 - Create Binary Tree From Descriptions

The problem asks us to construct a binary tree from a list of relationships, where each relationship is given as [parent, child, isLeft].

leetcodemediumarrayhash-tabletreebinary-tree
LeetCode 3250 - Find the Count of Monotonic Pairs I

The problem asks us to count the number of valid pairs of arrays (arr1, arr2) derived from a given array nums. Both arr1 and arr2 have the same length as nums. The constraints on these arrays are: 1. arr1 is non-decreasing. 2. arr2 is non-increasing. 3.

leetcodehardarraymathdynamic-programmingcombinatoricsprefix-sum
LeetCode 2566 - Maximum Difference by Remapping a Digit

The problem asks us to maximize the difference between two numbers that can be created from a given integer num through a specific remapping operation.

leetcodeeasymathgreedy
LeetCode 1900 - The Earliest and Latest Rounds Where Players Compete

The tournament is organized as a sequence of elimination rounds. In every round, players are paired symmetrically from the two ends of the current lineup. The first player faces the last player, the second player faces the second-to-last player, and so on.

leetcodeharddynamic-programmingmemoization
LeetCode 1981 - Minimize the Difference Between Target and Chosen Elements

This problem asks us to select exactly one element from each row of a given m x n integer matrix mat such that the sum of the selected elements is as close as possible to a given integer target.

leetcodemediumarraydynamic-programmingmatrix
CF 162A - Pentagonal numbers

We need to compute the n-th pentagonal number. Pentagonal numbers form a sequence generated by a direct mathematical formula: $$Pn = frac{3n^2 - n}{2}$$ The input contains a single integer n, and the output is the value of this formula for that position in the sequence.

codeforcescompetitive-programming*specialimplementation
CF 219B - Special Offer! Super Price 999 Bourles!

Polycarpus already knows the best regular price for his product, p. He is willing to reduce it by at most d bourles if that gives the final price a more attractive ending, specifically as many trailing nines as possible. A trailing nine means a digit 9 at the end of the number.

codeforcescompetitive-programmingimplementation
LeetCode 2783 - Flight Occupancy and Waitlist Analysis

This problem models airline flight bookings with limited seating capacity. The Flights table contains one row per flight. Each flight has a unique flightid and a capacity, which represents the maximum number of passengers that can be seated on that flight.

leetcodemediumdatabase
LeetCode 2492 - Minimum Score of a Path Between Two Cities

The problem asks us to find the minimum possible score of a path between city 1 and city n in a graph defined by n cities and roads. Each road connects two cities bidirectionally and has an associated distance.

leetcodemediumdepth-first-searchbreadth-first-searchunion-findgraph-theory
CF 204C - Little Elephant and Furik and Rubik

We are given two strings of equal length. From each string we independently pick a substring, and both substrings must have the same length. After choosing them, we compare them character by character and count how many positions match.

codeforcescompetitive-programmingmathprobabilities
CF 215B - Olympic Medal

We are designing a two-part medal. The outer part is a ring with outer radius $r1$ and inner radius $r2$. The inner part is a solid disk of radius $r2$. Both parts have the same thickness, so their masses depend only on area and density.

codeforcescompetitive-programminggreedymath
LeetCode 2395 - Find Subarrays With Equal Sum

The problem asks us to determine whether there exist two contiguous subarrays of length 2 in a given array nums that have the same sum. A subarray of length 2 is simply any consecutive pair of elements in the array.

leetcodeeasyarrayhash-table
LeetCode 2678 - Number of Senior Citizens

This problem asks us to count the number of passengers in a list who are strictly older than 60. Each passenger's information is compressed into a fixed-length string of 15 characters.

leetcodeeasyarraystring
LeetCode 2568 - Minimum Impossible OR

The problem asks us to find the smallest positive integer that cannot be represented as a bitwise OR of any subsequence of a given array nums. The input array contains positive integers, and the subsequences can have any length, including length 1.

leetcodemediumarraybit-manipulationbrainteaser
LeetCode 2460 - Apply Operations to an Array

This problem gives us a 0-indexed array nums containing non-negative integers. We must perform a sequence of operations on adjacent elements, then rearrange the resulting array by moving all zeros to the end. The first phase consists of processing the array from left to right.

leetcodeeasyarraytwo-pointerssimulation
LeetCode 2677 - Chunk Array

This problem asks us to split an input array into smaller subarrays, commonly called chunks, where each chunk has a fixed maximum size.

leetcodeeasy
LeetCode 3170 - Lexicographically Minimum String After Removing Stars

The problem asks us to transform a string s that may contain the '' character into a lexicographically smallest string by repeatedly applying a deletion operation. Specifically, for each '' in the string, we must remove it along with the smallest non-'' character to its left.

leetcodemediumhash-tablestringstackgreedyheap-(priority-queue)
LeetCode 2754 - Bind Function to Context

The problem is asking us to implement a polyfill for JavaScript's built-in Function.prototype.bind method. Specifically, we need to create a bindPolyfill method that can be called on any function.

leetcodemedium
LeetCode 2602 - Minimum Operations to Make All Array Elements Equal

The problem gives us an integer array nums and another array queries. For every query value q, we must calculate the minimum number of operations required to make every element in nums equal to q. One operation consists of increasing or decreasing a single element by exactly 1.

leetcodemediumarraybinary-searchsortingprefix-sum
LeetCode 2070 - Most Beautiful Item for Each Query

The problem gives us a list of items, where each item has two properties: - price - beauty Each entry looks like: We are also given a list of queries.

leetcodemediumarraybinary-searchsorting
LeetCode 2800 - Shortest String That Contains Three Strings

The problem asks us to construct a string that contains three given strings a, b, and c as substrings while minimizing its length. If multiple strings satisfy the minimum length condition, the lexicographically smallest one must be returned.

leetcodemediumstringgreedyenumeration
CF 406D - Hill Climbing

We are given a sequence of hills placed along a line. Each hill has a fixed horizontal position and a height, and we imagine it as a vertical segment rising from the ground.

codeforcescompetitive-programmingdfs-and-similargeometrytrees
LeetCode 2611 - Mice and Cheese

The problem gives us two arrays, reward1 and reward2, where each index represents a specific type of cheese. Every cheese must be eaten by exactly one of the two mice. If cheese i is eaten by the first mouse, we gain reward1[i] points.

leetcodemediumarraygreedysortingheap-(priority-queue)
LeetCode 2329 - Product Sales Analysis V

This problem asks us to calculate how much money each user has spent across all of their purchases. We are given two database tables: The Sales table stores purchase records.

leetcodeeasydatabase
LeetCode 2935 - Maximum Strong Pair XOR II

The problem asks us to find the maximum XOR value of a strong pair in a given array of integers nums. A pair (x, y) is considered strong if it satisfies the condition |x - y| <= min(x, y).

leetcodehardarrayhash-tablebit-manipulationtriesliding-window
LeetCode 3045 - Count Prefix and Suffix Pairs II

The problem asks us to count the number of ordered pairs (i, j) in a list of strings words such that i < j and words[i] is both a prefix and a suffix of words[j].

leetcodehardarraystringtrierolling-hashstring-matchinghash-function
CF 240F - TorCoder

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.

codeforcescompetitive-programmingdata-structures
LeetCode 3023 - Find Pattern in Infinite Stream I

The problem asks us to detect the first occurrence of a given binary pattern within an infinite stream of bits. We are given an object stream that allows us to read one bit at a time using the next() function.

leetcodemediumarraysliding-windowrolling-hashstring-matchinginteractivehash-function
LeetCode 2430 - Maximum Deletions on a String

The problem gives us a string s consisting only of lowercase English letters. We want to completely delete the string using the maximum possible number of operations. In a single operation, we have two possible actions: 1. Delete the entire remaining string immediately. 2.

leetcodehardstringdynamic-programmingrolling-hashstring-matchinghash-function
CF 263C - Circle of Numbers

We are given a hidden cyclic arrangement of the integers from 1 to n placed around a circle. From this arrangement, someone constructed a set of ordered pairs describing connections between values.

codeforcescompetitive-programmingbrute-forcedfs-and-similarimplementation
LeetCode 2872 - Maximum Number of K-Divisible Components

This problem is asking us to split a given undirected tree into as many connected components as possible, under the condition that the sum of values of nodes in each component is divisible by a given integer k.

leetcodehardtreedepth-first-search
LeetCode 2594 - Minimum Time to Repair Cars

The problem gives us a list of mechanics, where each mechanic has a specific rank. A mechanic with rank r takes r n^2 minutes to repair n cars. This means the repair time grows quadratically as the number of assigned cars increases.

leetcodemediumarraybinary-search
LeetCode 2551 - Put Marbles in Bags

The problem asks us to distribute weights.length marbles into k contiguous bags, where the cost of a bag is defined as the sum of the first and last marble in that bag.

leetcodehardarraygreedysortingheap-(priority-queue)
CF 141E - Clearing Up

We are given an undirected graph where every edge already belongs to one of two categories. Roads marked "S" are narrow roads that the Elf clears, and roads marked "M" are wide roads that Santa clears. We must choose a subset of roads satisfying two conditions at the same time.

codeforcescompetitive-programmingconstructive-algorithmsdpdsugraphs
CF 254A - Cards with Numbers

We have 2n cards laid out in a sequence. Every card has an integer written on it, and each card also has an index from 1 to 2n. The task is to divide all cards into exactly n pairs such that both cards inside every pair contain the same number.

codeforcescompetitive-programmingconstructive-algorithmssortings
CF 163B - Lemmings

We are asked to select k lemmings from a group of n and assign them to k ledges of increasing heights so that heavier lemmings occupy higher ledges, while minimizing the time t needed for all selected lemmings to reach their assigned ledges.

codeforcescompetitive-programmingbinary-search
LeetCode 2135 - Count Words Obtained After Adding a Letter

The problem requires us to determine how many strings in targetWords can be formed from strings in startWords through a specific transformation.

leetcodemediumarrayhash-tablestringbit-manipulationsorting
LeetCode 2860 - Happy Students

The problem asks us to determine the number of ways to select a subset of students from a class such that every student is happy according to the given rules. Each student has a number nums[i] that represents a threshold.

leetcodemediumarraysortingenumeration
LeetCode 3332 - Maximum Points Tourist Can Earn

The problem asks us to maximize the points a tourist can earn over a fixed number of days, k, while visiting n cities.

leetcodemediumarraydynamic-programmingmatrix
LeetCode 2182 - Construct String With Repeat Limit

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.

leetcodemediumhash-tablestringgreedyheap-(priority-queue)counting
LeetCode 1803 - Count Pairs With XOR in a Range

The problem gives us an integer array nums and two integers, low and high. We need to count how many index pairs (i, j) satisfy two conditions: - i < j - low <= nums[i] XOR nums[j] <= high The XOR operation compares bits between two numbers.

leetcodehardarraybit-manipulationtrie
CF 306B - Optimizer

We are given a linear memory array of size n and a set of m instructions, each of which sets a contiguous block of memory to the value 13. The instructions are indexed in the input order. Some instructions may overlap, fully or partially, with others.

codeforcescompetitive-programmingdata-structuresgreedysortings
CF 354A - Vasya and Robot

Vasya has a line of items, each with a specific weight, and he wants a robot to pick all of them using its two arms. The left arm can take the leftmost item and the right arm can take the rightmost item.

codeforcescompetitive-programmingbrute-forcegreedymath
LeetCode 3038 - Maximum Number of Operations With the Same Score I

The problem asks us to repeatedly perform an operation on an integer array nums. In each operation, we remove the first two elements of the array and compute a score, which is simply the sum of those two removed values.

leetcodeeasyarraysimulation
LeetCode 3127 - Make a Square with the Same Color

This problem gives us a fixed 3 x 3 grid containing only two possible characters, 'B' for black and 'W' for white. We are allowed to change the color of at most one cell.

leetcodeeasyarraymatrixenumeration
LeetCode 2814 - Minimum Time Takes to Reach Destination Without Drowning

This problem takes place on a two-dimensional grid where each cell represents a type of terrain. The grid contains: - "S": your starting position. - "D": the destination you want to reach. - ".": an empty cell that can be walked on. - "X": a stone cell that cannot be entered.

leetcodehardarraybreadth-first-searchmatrix
CF 151B - Phone Numbers

Each friend has a phone book containing numbers written in the format XX-XX-XX. Every phone number belongs to exactly one of three categories. A taxi number uses the same digit everywhere. Examples are 11-11-11 or 55-55-55.

codeforcescompetitive-programmingimplementationstrings
LeetCode 2615 - Sum of Distances

The problem asks us to compute, for every index i in the array nums, the total distance between i and every other index j where nums[j] == nums[i]. More formally, for each position i, we need to calculate: for all indices j such that: - nums[j] == nums[i] - j !

leetcodemediumarrayhash-tableprefix-sum
LeetCode 2837 - Total Traveled Distance

The problem requires calculating the total distance traveled by each user based on ride data stored in a relational database. We are given two tables: Users and Rides. The Users table contains userid and name, where userid is unique.

leetcodeeasydatabase
LeetCode 2250 - Count Number of Rectangles Containing Each Point

Here is the complete, detailed technical solution guide for LeetCode 2250 - Count Number of Rectangles Containing Each Point in a single, comprehensive response. The problem provides two arrays: rectangles and points.

leetcodemediumarrayhash-tablebinary-searchbinary-indexed-treesorting
LeetCode 3177 - Find the Maximum Length of a Good Subsequence II

We are given an integer array nums and a non-negative integer k. We must find the maximum possible length of a subsequence such that the number of adjacent unequal pairs is at most k.

leetcodehardarrayhash-tabledynamic-programming
LeetCode 3211 - Generate Binary Strings Without Adjacent Zeros

The problem asks us to generate every binary string of length n such that no substring of length 2 contains two consecutive zeros. A binary string contains only the characters "0" and "1". A substring of length 2 means every adjacent pair of characters in the string.

leetcodemediumstringbacktrackingbit-manipulation
CF 145C - Lucky Subsequence

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.

codeforcescompetitive-programmingcombinatoricsdpmath
CF 172B - Pseudorandom Sequence Period

We are given a linear congruential generator, a classic pseudorandom sequence formula: $$ri = (a cdot r{i-1} + b) bmod m$$ The sequence starts from r0, and every next value is computed from the previous one.

codeforcescompetitive-programming*specialimplementationnumber-theory
LeetCode 2580 - Count Ways to Group Overlapping Ranges

The problem gives us a list of integer ranges, where each range represents all integers between start and end, inclusive. We must divide all ranges into exactly two groups. Either group may be empty. The important restriction is that overlapping ranges cannot be separated.

leetcodemediumarraysorting
LeetCode 2810 - Faulty Keyboard

In this problem, we are given a string s that represents characters typed on a faulty keyboard. Most characters behave normally and are appended to the current text on the screen. However, whenever the character 'i' is typed, the keyboard does not insert the character itself.

leetcodeeasystringsimulation
CF 303B - Rectangle Puzzle II

We have a grid-aligned rectangle of size n × m. Every valid point has integer coordinates between (0, 0) and (n, m). We must choose another axis-aligned rectangle inside it. The rectangle is described by four integers (x1, y1, x2, y2).

codeforcescompetitive-programmingimplementationmath
CF 248A - Cupboards

We are given a set of cupboards, each with two doors: left and right. Each door can be either open or closed. The initial state of each door is given in the input. Karlsson wants all left doors to be in the same position and all right doors to be in the same position.

codeforcescompetitive-programmingimplementation
LeetCode 1984 - Minimum Difference Between Highest and Lowest of K Scores

The problem asks us to find the minimum possible difference between the highest and lowest scores when selecting exactly k scores from an array of student scores.

leetcodeeasyarraysliding-windowsorting
CF 233B - Non-square Equation

This is a Type B - “Prove that / determine a value” problem. The task is to deduce a uniquely determined numerical quantity from the hypotheses.

codeforcescompetitive-programmingbinary-searchbrute-forcemath
LeetCode 3323 - Minimize Connected Groups by Inserting Interval

The problem asks us to minimize the number of connected groups in a set of intervals by adding exactly one interval of length at most k. Each interval [start, end] represents a continuous range on the number line.

leetcodemediumarraybinary-searchsliding-windowsorting
LeetCode 1937 - Maximum Number of Points with Cost

The problem gives us an m x n matrix called points. We must choose exactly one cell from every row. The value of the chosen cell is added to our score. However, there is a movement penalty between consecutive rows.

leetcodemediumarraydynamic-programmingmatrix
LeetCode 2899 - Last Visited Integers

The problem gives us an integer array nums that contains either positive integers or the value -1. We process the array from left to right while maintaining two conceptual arrays: - seen, which stores previously encountered positive integers - ans, which stores the answers for…

leetcodeeasyarraysimulation
LeetCode 2173 - Longest Winning Streak

This problem is asking us to determine the longest sequence of consecutive wins, also called a winning streak, for each player in a match history. The input is a Matches table with three columns: playerid, matchday, and result.

leetcodeharddatabase
LeetCode 2878 - Get the Size of a DataFrame

The problem asks us to determine the size of a DataFrame named players. Specifically, it requires computing two values: the number of rows and the number of columns.

leetcodeeasy
LeetCode 1958 - Check if Move is Legal

This problem asks us to determine whether a move in a board game is legal based on specific line rules. The board is an 8 x 8 matrix where cells can be empty '.', white 'W', or black 'B'.

leetcodemediumarraymatrixenumeration
LeetCode 2272 - Substring With Largest Variance

This problem asks us to find the maximum possible variance among all substrings of a given string. The string contains only lowercase English letters, and the variance of a substring is defined as the largest difference between the counts of any two characters that both appear…

leetcodehardhash-tablestringdynamic-programmingenumeration
CF 203C - Photographer

Each client describes a fixed amount of work Valera must perform: a certain number of low quality photos and a certain number of high quality photos.

codeforcescompetitive-programminggreedysortings
CF 427E - Police Patrol

All criminals stand on the x-axis, and we must choose one integer coordinate for the police station. The patrol car starts from the station, visits some criminals, brings them back to the station, then repeats until everyone is arrested. Each trip can carry at most m criminals.

codeforcescompetitive-programminggreedyimplementationmathternary-search
LeetCode 2325 - Decode the Message

This problem is asking us to decode a secret message using a substitution cipher defined by a key string. The key string may include spaces and contains every lowercase letter of the English alphabet at least once.

leetcodeeasyhash-tablestring
LeetCode 2751 - Robot Collisions

This problem describes a simulation of robots moving on a one-dimensional line, each with a given starting position, health, and direction. Every robot moves at the same speed, and collisions occur when two robots meet at the same position.

leetcodehardarraystacksortingsimulation
CF 243E - Matrix

We are given a square grid of size $n times n$, where every cell contains either 0 or 1. The operation allowed is to permute the columns arbitrarily.

codeforcescompetitive-programmingdata-structures
CF 245E - Mishap in Club

We are given a chronological log of a single night in a club. Every character in the input string represents one event: a “+” means someone entered the club, and a “-” means someone left.

codeforcescompetitive-programminggreedyimplementation
LeetCode 2335 - Minimum Amount of Time to Fill Cups

The problem gives us an array amount of length 3. Each index represents the number of cups that need to be filled for a specific water type: - amount[0] represents cold water cups - amount[1] represents warm water cups - amount[2] represents hot water cups Every second, the…

leetcodeeasyarraygreedysortingheap-(priority-queue)
LeetCode 3277 - Maximum XOR Score Subarray Queries

The problem gives us an integer array nums and several range queries. For each query [li, ri], we must examine every possible subarray fully contained inside nums[li..ri] and return the maximum XOR score among them.

leetcodehardarraydynamic-programming
LeetCode 2983 - Palindrome Rearrangement Queries

We are given a string s of even length n. For every query, we are allowed to independently rearrange two specific substrings: - One substring lies completely inside the left half of the string. - The other substring lies completely inside the right half of the string.

leetcodehardhash-tablestringprefix-sum
CF 263A - Beautiful Matrix

We are given a fixed 5 by 5 grid that contains mostly zeros and exactly one cell containing a one. In one move, we are allowed to swap adjacent rows or swap adjacent columns. Each such swap moves the entire row or column by exactly one position.

codeforcescompetitive-programmingimplementation
LeetCode 3322 - Premier League Table Ranking III

The problem requires calculating a Premier League-style ranking for teams in each season based on their match results.

leetcodemediumdatabase
CF 229B - Planets

We are given an undirected weighted graph of planets connected by stargates. Jack starts on planet 1 at time 0 and wants to reach planet n as early as possible. Moving through a stargate takes a fixed positive amount of time. The unusual part is the waiting rule.

codeforcescompetitive-programmingbinary-searchdata-structuresgraphsshortest-paths
CF 267B - Dominoes

We are given a set of domino tiles, each with two numbers on its halves. The task is to arrange all dominoes in a sequence so that the touching halves of adjacent dominoes have the same number. A domino can be flipped, which swaps its two numbers.

codeforcescompetitive-programmingdfs-and-similargraphs
LeetCode 1989 - Maximum Number of People That Can Be Caught in Tag

The problem describes a line of people represented by a binary array team, where each index corresponds to a person. A value of 1 indicates a person who is “it”, and a value of 0 indicates a person who is not “it”.

leetcodemediumarraytwo-pointersgreedy
LeetCode 3113 - Find the Number of Subarrays Where Boundary Elements Are Maximum

We are given an array nums of positive integers. We need to count how many contiguous subarrays satisfy a very specific condition: - The first element of the subarray and the last element of the subarray must both be equal to the maximum value inside that subarray.

leetcodehardarraybinary-searchstackmonotonic-stack
LeetCode 2463 - Minimum Total Distance Traveled

Here is a comprehensive, reference-quality solution guide for LeetCode 2463 - Minimum Total Distance Traveled following your formatting requirements.

leetcodehardarraydynamic-programmingsorting
LeetCode 3245 - Alternating Groups III

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.

leetcodehardarraybinary-indexed-treeordered-set
LeetCode 1998 - GCD Sort of an Array

The problem asks whether it is possible to sort an integer array nums into non-decreasing order using a very specific type of swap. You can swap any two elements nums[i] and nums[j] if and only if their greatest common divisor (GCD) is greater than 1.

leetcodehardarraymathunion-findsortingnumber-theory
LeetCode 1976 - Number of Ways to Arrive at Destination

This problem gives us a weighted, undirected graph. Each intersection is a node, and each road is an edge with a travel time. We start at intersection 0 and want to reach intersection n - 1. The important detail is that we are not simply looking for the shortest distance.

leetcodemediumdynamic-programminggraph-theorytopological-sortshortest-path
LeetCode 1905 - Count Sub Islands

The problem presents two m x n binary matrices, grid1 and grid2, representing maps of land (1) and water (0). Each matrix may contain multiple islands, where an island is defined as a connected group of 1s that are adjacent vertically or horizontally.

leetcodemediumarraydepth-first-searchbreadth-first-searchunion-findmatrix
LeetCode 3292 - Minimum Number of Valid Strings to Form Target II

We are given a collection of strings words and a target string target. A string is considered valid if it is a prefix of at least one word in words. This means that for every word, all of its prefixes are available for use.

leetcodehardarraystringbinary-searchdynamic-programminggreedysegment-treerolling-hashstring-matchinghash-function