brain

tamnd's digital brain — notes, problems, research

42627 notes

LeetCode 2453 - Destroy Sequential Targets

The problem presents a scenario where we have a list of positive integers nums representing targets placed on a number line. We also have an integer space representing the step interval of a machine.

leetcodemediumarrayhash-tablecounting
CF 162G - Non-decimal sum

We are given several integers written in an arbitrary base between 2 and 36. Digits above 9 are represented with uppercase letters, so in base 16 the digit sequence continues as A, B, C, D, E, F, and in larger bases it may continue up to Z.

codeforcescompetitive-programming*special
LeetCode 2607 - Make K-Subarray Sums Equal

The problem asks us to transform a circular integer array so that every subarray of length k has the same sum. A circular array means the end wraps around to the beginning, so subarrays can cross the boundary of the array.

leetcodemediumarraymathgreedysortingnumber-theory
LeetCode 3194 - Minimum Average of Smallest and Largest Elements

The problem gives us an even-length integer array nums. We repeatedly perform the following operation until the array becomes empty: 1. Remove the smallest element. 2. Remove the largest element. 3. Compute their average. 4. Store that average in another array called averages.

leetcodeeasyarraytwo-pointerssorting
CF 139A - Petr and Book

Petr has a book with n pages. Starting from Monday, he reads a fixed number of pages each day of the week. The input gives those seven daily reading capacities in order from Monday to Sunday. We need to determine on which day Petr finishes the book.

codeforcescompetitive-programmingimplementation
CF 160C - Find Pair

We are given an array of n integers. From this array, we form every ordered pair (a[i], a[j]), including pairs where i = j. Since both positions are chosen independently, there are exactly n² pairs. All these pairs are sorted lexicographically.

codeforcescompetitive-programmingimplementationmathsortings
LeetCode 1884 - Egg Drop With 2 Eggs and N Floors

This problem asks us to determine the minimum number of moves required to identify a critical floor f in a building with n floors, using exactly two eggs. The critical floor f has the following meaning: - Any egg dropped from a floor higher than f will break.

leetcodemediummathdynamic-programming
LeetCode 2644 - Find the Maximum Divisibility Score

The problem asks us to identify, from a list of divisors, the integer that has the maximum divisibility score with respect to a given array of numbers. The divisibility score of a divisor is defined as the count of elements in nums that are divisible by that divisor.

leetcodeeasyarray
LeetCode 1944 - Number of Visible People in a Queue

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.

leetcodehardarraystackmonotonic-stack
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 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 3123 - Find Edges in Shortest Paths

The problem gives us an undirected weighted graph with n nodes and m edges. Each edge connects two nodes and has a positive weight. We need to determine which edges belong to at least one shortest path from node 0 to node n - 1.

leetcodeharddepth-first-searchbreadth-first-searchgraph-theoryheap-(priority-queue)shortest-path
CF 150D - Mission Impassable

We start with a string of length l. In one move we may choose any contiguous substring that is a palindrome and whose length k is allowed, meaning a[k] != -1. After deleting it, the remaining characters concatenate together. The score gained from this move is a[k].

codeforcescompetitive-programmingdpstrings
LeetCode 2887 - Fill Missing Data

The problem provides a Pandas DataFrame named products with three columns: | Column | Type | | --- | --- | | name | object | | quantity | int | | price | int | The task is to replace all missing values in the quantity column with 0.

leetcodeeasy
LeetCode 2238 - Number of Times a Driver Was a Passenger

The problem provides a table Rides that records rides between drivers and passengers. Each row has a unique rideid, a driverid, and a passengerid. The task is to determine, for each driver, how many times that driver has appeared as a passenger in the table.

leetcodemediumdatabase
LeetCode 1985 - Find the Kth Largest Integer in the Array

This problem asks us to find the kth largest value among a list of integers that are represented as strings. Each element in nums is a non-negative integer encoded as a string with no leading zeros, and we are required to return the kth largest value according to numeric order…

leetcodemediumarraystringdivide-and-conquersortingheap-(priority-queue)quickselect
LeetCode 2950 - Number of Divisible Substrings

The problem asks us to analyze a given string word where each lowercase English letter is mapped to a digit according to a classic phone keypad scheme.

leetcodemediumhash-tablestringcountingprefix-sum
LeetCode 3269 - Constructing Two Increasing Arrays

We are given two binary arrays, nums1 and nums2. Each element is either 0 or 1. We must replace every value with a positive integer according to its parity: - Every 0 must become an even positive integer. - Every 1 must become an odd positive integer.

leetcodehardarraydynamic-programming
LeetCode 2647 - Color the Triangle Red

The problem asks us to determine the minimal set of initial triangles to color red in an equilateral triangle of side length n, such that by repeatedly applying a propagation rule, all triangles eventually become red.

leetcodehardarraymath
LeetCode 2152 - Minimum Number of Lines to Cover Points

This problem asks us to determine the minimum number of straight lines needed to cover a given set of points on an X-Y plane. Each point is defined by its (x, y) coordinates, and a straight line can pass through any number of points as long as they are collinear.

leetcodemediumarrayhash-tablemathdynamic-programmingbacktrackingbit-manipulationgeometrybitmask
LeetCode 2714 - Find Shortest Path with K Hops

This problem gives us an undirected weighted graph with n nodes and a list of weighted edges. Each edge connects two nodes and has a positive weight. We are also given a source node s, a destination node d, and an integer k.

leetcodehardgraph-theoryheap-(priority-queue)shortest-path
LeetCode 2428 - Maximum Sum of an Hourglass

The problem provides an m x n integer matrix grid and asks for the maximum sum of an hourglass shape within the matrix. An hourglass is defined as a 3x3 structure with the top and bottom rows fully included, and only the center element from the middle row.

leetcodemediumarraymatrixprefix-sum
LeetCode 2435 - Paths in Matrix Whose Sum Is Divisible by K

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.

leetcodehardarraydynamic-programmingmatrix
LeetCode 2539 - Count the Number of Good Subsequences

LeetCode 2539: Count the Number of Good Subsequences (Medium)

leetcodemediumhash-tablemathstringcombinatoricscounting
LeetCode 2433 - Find The Original Array of Prefix Xor

The problem is asking us to reverse-engineer an array arr from its prefix XOR array pref. Specifically, pref[i] represents the XOR of all elements in arr from index 0 to i. Our goal is to reconstruct arr given only pref.

leetcodemediumarraybit-manipulation
LeetCode 1932 - Merge BSTs to Create Single BST

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.

leetcodehardarrayhash-tabletreedepth-first-searchbinary-search-treebinary-tree
LeetCode 3115 - Maximum Prime Difference

The problem gives us an integer array nums, and we need to find the maximum distance between the indices of any two prime numbers in the array. More specifically, we are interested in indices i and j such that both nums[i] and nums[j] are prime numbers.

leetcodemediumarraymathnumber-theory
CF 338D - GCD Table

We are asked to determine whether a given sequence of numbers appears as consecutive elements in some row of a hypothetical GCD table. The table has n rows and m columns, where each element at row i and column j is the greatest common divisor of i and j.

codeforcescompetitive-programmingchinese-remainder-theoremmathnumber-theory
CF 142E - Help Greg the Dwarf 2

We are asked to find the shortest distance between two points on a cone, where the cone has a circular base of radius r and height h, and the points may lie anywhere on the cone's lateral surface or the base.

codeforcescompetitive-programminggeometry
LeetCode 3149 - Find the Minimum Cost Array Permutation

The problem presents an array nums of length n that is a permutation of integers from 0 to n - 1. We are asked to find a permutation perm of the same range [0, 1, 2, ...

leetcodehardarraydynamic-programmingbit-manipulationbitmask
LeetCode 2504 - Concatenate the Name and the Profession

The problem asks us to transform data in a SQL table named Person. Each row represents a person, with three columns: personid, name, and profession.

leetcodeeasydatabase
LeetCode 2516 - Take K of Each Character From Left and Right

The problem asks us to determine the minimum number of characters to take from either end of a string s consisting only of the letters 'a', 'b', and 'c' so that we collect at least k of each character.

leetcodemediumhash-tablestringsliding-window
LeetCode 2255 - Count Prefixes of a Given String

The problem asks us to determine how many strings in a given array words are prefixes of a target string s. A prefix of a string is defined as any substring that starts at the first character and continues for any length up to the length of the string itself.

leetcodeeasyarraystring
LeetCode 1977 - Number of Ways to Separate Numbers

The problem asks us to determine the number of ways a string of digits, num, can be split into a sequence of positive integers that are non-decreasing and have no leading zeros.

leetcodehardstringdynamic-programmingsuffix-array
LeetCode 3370 - Smallest Number With All Set Bits

The problem asks us to find the smallest integer x such that: 1. x = n 2. Every bit in the binary representation of x is set to 1 A number whose binary representation contains only set bits looks like this: - 1 → binary "1" - 3 → binary "11" - 7 → binary "111" - 15 →…

leetcodeeasymathbit-manipulation
LeetCode 2689 - Extract Kth Character From The Rope Tree

Edit This problem asks us to retrieve the k-th character from a string represented by a special binary tree called a rope tree. Instead of storing one large string directly, the string is distributed across the tree structure.

leetcodeeasytreedepth-first-searchbinary-tree
CF 242B - Big Segment

We are given a list of segments on a number line, each defined by a left and right endpoint. The task is to find if there exists a single segment among them that fully contains every other segment.

codeforcescompetitive-programmingimplementationsortings
CF 153C - Caesar Cipher

We are asked to implement a Caesar cipher on an input string of uppercase Latin letters. Conceptually, this means each letter is shifted forward in the alphabet by a fixed number of positions, denoted by k. If the shift goes past 'Z', it wraps around to 'A'.

codeforcescompetitive-programming*special
LeetCode 2992 - Number of Self-Divisible Permutations

The problem asks us to count how many permutations of the numbers 1 through n satisfy a special condition called self-divisible. We start with the array: We must rearrange these numbers into every possible permutation, then determine whether the permutation is valid.

leetcodemediumarraymathdynamic-programmingbacktrackingbit-manipulationnumber-theorybitmask
LeetCode 1971 - Find if Path Exists in Graph

The problem asks us to determine whether a path exists between two nodes in an undirected graph. The graph is defined by n vertices labeled from 0 to n - 1 and a list of edges, where each edge connects two distinct vertices.

leetcodeeasydepth-first-searchbreadth-first-searchunion-findgraph-theory
LeetCode 1852 - Distinct Numbers in Each Subarray

The problem gives us an integer array nums and an integer k. For every contiguous subarray of length k, we must determine how many unique values appear inside that window. A subarray is a continuous portion of the array.

leetcodemediumarrayhash-tablesliding-window
CF 149D - Coloring Brackets

We are given a valid parenthesis sequence. Every opening bracket has a unique matching closing bracket, and the pairs are properly nested. We want to assign colors to brackets under two rules.

codeforcescompetitive-programmingdp
LeetCode 2388 - Change Null Values in a Table to the Previous Value

The problem asks us to process a database table, CoffeeShop, which contains two columns: id and drink. Each row represents a drink order. Some drink values may be NULL.

leetcodemediumdatabase
CF 143A - Help Vasilisa the Wise 2

We need to fill a 2 x 2 grid with four distinct digits from 1 to 9. The grid looks like this: $$begin{matrix} a & b c & d end{matrix}$$ The input gives us six sums.

codeforcescompetitive-programmingbrute-forcemath
LeetCode 2424 - Longest Uploaded Prefix

The problem asks us to design a data structure that tracks uploaded videos and continuously reports the length of the longest uploaded prefix. A prefix of uploaded videos means that every video from 1 through i has already been uploaded. The goal is to return the maximum such i.

leetcodemediumhash-tablebinary-searchunion-finddesignbinary-indexed-treesegment-treeheap-(priority-queue)ordered-set
CF 187D - BRT Contract

A bus travels through a fixed sequence of road segments. Between consecutive segments there are traffic lights, and every light follows the same synchronized cycle. Each cycle lasts g + r seconds.

codeforcescompetitive-programmingdata-structures
CF 429B - Working out

We have a two-dimensional gym represented as a grid of size n × m. Each cell contains a positive integer representing the calories burned by doing the workout at that location.

codeforcescompetitive-programmingdp
LeetCode 2988 - Manager of the Largest Department

You included two different problems in one message, and the second prompt overrides the first at the end. I will answer for LeetCode 2988 - Manager of the Largest Department.

leetcodemediumdatabase
CF 226D - The table

We are given a rectangular table of integers with $n$ rows and $m$ columns. Each cell contains a number that could be positive, negative, or zero. Harry can perform two types of operations: flip the sign of all numbers in a row or flip the sign of all numbers in a column.

codeforcescompetitive-programmingconstructive-algorithmsgreedy
CF 446D - DZY Loves Games

We are given an undirected connected graph representing a maze of rooms. DZY starts at room 1 with a fixed number of lives. Each time he is in a room, he randomly chooses one of its outgoing corridors uniformly and moves to the adjacent room.

codeforcescompetitive-programmingmathmatricesprobabilities
CF 139B - Wallpaper

We are asked to compute the minimum cost to paper all walls in an apartment where each room is a rectangular prism. For each room, the length, width, and height are given. The perimeter of a room determines how many strips of wallpaper are needed.

codeforcescompetitive-programmingimplementationmath
LeetCode 3134 - Find the Median of the Uniqueness Array

The problem defines a special array called the uniqueness array. For every possible subarray of nums, we compute how many distinct values appear inside that subarray. We then collect all of those distinct counts into a single array and sort it in non decreasing order.

leetcodehardarrayhash-tablebinary-searchsliding-window
LeetCode 3243 - Shortest Distance After Road Addition Queries I

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 - ...

leetcodemediumarraybreadth-first-searchgraph-theory
LeetCode 3061 - Calculate Trapping Rain Water

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.

leetcodeharddatabase
CF 417A - Elimination

We are organizing a programming competition where the goal is to select at least $n cdot m$ finalists. Participants can qualify in three ways: first, by winning one of the main elimination rounds, which has $c$ problems and produces $n$ winners; second, by winning one of the…

codeforcescompetitive-programmingdpimplementationmath
CF 160D - Edges in MST

We are given a connected weighted undirected graph with no loops or multiple edges. Each edge has a positive weight.

codeforcescompetitive-programmingdfs-and-similardsugraphssortings
LeetCode 2648 - Generate Fibonacci Sequence

The problem asks us to implement a generator function that yields numbers from the Fibonacci sequence. The Fibonacci sequence is defined recursively as Xn = Xn-1 + Xn-2 with the starting values X0 = 0 and X1 = 1.

leetcodeeasy
LeetCode 2825 - Make String a Subsequence Using Cyclic Increments

The problem gives us two lowercase strings, str1 and str2. We are allowed to perform at most one global operation on str1. During this operation, we may choose any subset of indices in str1, and increment the character at each chosen index by one alphabetically.

leetcodemediumtwo-pointersstring
LeetCode 3326 - Minimum Division Operations to Make Array Non Decreasing

The problem asks us to make a given integer array nums non-decreasing by performing a specific type of operation any number of times. Each operation consists of selecting an element and dividing it by its greatest proper divisor.

leetcodemediumarraymathgreedynumber-theory
LeetCode 3302 - Find the Lexicographically Smallest Valid Sequence

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.

leetcodemediumtwo-pointersstringdynamic-programminggreedy
CF 157B - Trace

The problem presents a scenario where a wall is decorated with multiple concentric circles, some of which are painted red while others are blue in an alternating pattern. The outermost area beyond the largest circle is always blue.

codeforcescompetitive-programminggeometrysortings
CF 416E - President's Path

We are given a graph with n cities connected by m bidirectional roads, each with a positive length. The goal is to determine, for every pair of cities (s, t) with s < t, how many roads can appear on at least one shortest path from s to t.

codeforcescompetitive-programmingdpgraphsshortest-paths
LeetCode 1863 - Sum of All Subset XOR Totals

This problem asks us to compute the sum of the XOR values of every possible subset of a given array. A subset is formed by choosing any combination of elements from the array, including the empty subset and the full array itself.

leetcodeeasyarraymathbacktrackingbit-manipulationcombinatoricsenumeration
CF 230A - Dragons

Kirito starts with some initial strength and must defeat every dragon on the level. Each dragon has two values: the minimum strength needed to beat it, and the bonus strength Kirito gains afterward.

codeforcescompetitive-programminggreedysortings
LeetCode 3000 - Maximum Area of Longest Diagonal Rectangle

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.

leetcodeeasyarray
LeetCode 3204 - Bitwise User Permissions Analysis

The problem is asking us to analyze a table of user permissions where each user's permissions are encoded as an integer. Each bit in this integer represents a distinct access level or feature.

leetcodemediumdatabase
LeetCode 2925 - Maximum Score After Applying Operations on a Tree

The problem gives us an undirected tree with n nodes rooted at node 0. Every node has an associated positive value. We may repeatedly perform an operation where we choose a node, add its current value to our score, and then permanently set that node's value to 0.

leetcodemediumdynamic-programmingtreedepth-first-search
LeetCode 3138 - Minimum Length of Anagram Concatenation

The problem gives us a string s that was formed by concatenating several strings together, where every piece is an anagram of the same unknown string t. Our task is to determine the minimum possible length of t.

leetcodemediumhash-tablestringcounting
LeetCode 2375 - Construct Smallest Number From DI String

The problem asks us to construct the lexicographically smallest number from a string pattern consisting of 'I' and 'D'.

leetcodemediumstringbacktrackingstackgreedy
CF 160E - Buses and People

Each bus is active at exactly one moment in time. A bus starting at stop s and ending at stop f can carry any passenger whose trip interval [l, r] is fully contained inside [s, f]. A person arrives at stop l at time b, so they can only use buses whose time t satisfies t = b.

codeforcescompetitive-programmingbinary-searchdata-structuressortings
LeetCode 2472 - Maximum Number of Non-overlapping Palindrome Substrings

The problem asks us to find the maximum number of non-overlapping palindrome substrings in a given string s such that each substring has a length of at least k.

leetcodehardtwo-pointersstringdynamic-programminggreedy
LeetCode 2519 - Count the Number of K-Big Indices

This problem asks us to determine how many indices in an array satisfy a very specific condition related to smaller values on both sides. For an index i to be considered k-big, two separate requirements must both hold: 1.

leetcodehardarraybinary-searchdivide-and-conquerbinary-indexed-treesegment-treemerge-sortordered-set
CF 253D - Table with Letters - 2

We are given a rectangular grid of characters, each cell containing a lowercase English letter. The task is to count how many axis-aligned subrectangles have two properties at the same time.

codeforcescompetitive-programmingbrute-forcetwo-pointers
LeetCode 2434 - Using a Robot to Print the Lexicographically Smallest String

In this problem, we are given a string s and a robot that manages another temporary string t. Initially, t is empty. The robot repeatedly performs one of two allowed operations: First, it may remove the first character from s and append it to the end of t.

leetcodemediumhash-tablestringstackgreedy
LeetCode 2470 - Number of Subarrays With LCM Equal to K

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.

leetcodemediumarraymathnumber-theory
LeetCode 2443 - Sum of Number and Its Reverse

Here’s a complete, detailed solution guide for LeetCode 2443 - Sum of Number and Its Reverse, fully following your formatting rules.

leetcodemediummathenumeration
LeetCode 3289 - The Two Sneaky Numbers of Digitville

The problem is asking us to identify two numbers that appear twice in an otherwise consecutive list of integers ranging from 0 to n - 1.

leetcodeeasyarrayhash-tablemath
LeetCode 2627 - Debounce

This problem asks us to implement a utility function called debounce. The function receives two inputs: - A function fn - A delay value t in milliseconds The goal is to return a new function, called the debounced version of fn.

leetcodemedium
CF 305D - Olya and Graph

We are given a directed acyclic graph with vertices numbered from 1 to n, where every edge goes from a smaller-numbered vertex to a larger-numbered vertex. Some edges already exist, and we are allowed to add more edges under certain constraints.

codeforcescompetitive-programmingcombinatoricsmath
LeetCode 2109 - Adding Spaces to a String

The problem requires us to insert spaces into a given string s at specific positions described by the array spaces. Each element in spaces represents an index in the string before which a space should be inserted.

leetcodemediumarraytwo-pointersstringsimulation
CF 186A - Comparing Strings

We are given two strings representing the genomes of two dwarves. The goal is to determine whether these two genomes could belong to the same race under a very specific definition: the first genome can be transformed into the second genome by swapping exactly two characters in…

codeforcescompetitive-programmingimplementationstrings
CF 253E - Printer

We are simulating a single-threaded printer that receives tasks over time. Each task arrives at a given time, has a known number of pages, and a priority that determines the order in which it is served when multiple tasks are waiting.

codeforcescompetitive-programmingbinary-searchdata-structuresimplementationsortings
LeetCode 2242 - Maximum Score of a Node Sequence

The problem gives us an undirected graph with n nodes. Each node has a score, and the graph edges define which nodes are directly connected. We must find a valid sequence of exactly four distinct nodes such that every adjacent pair in the sequence has an edge between them.

leetcodehardarraygraph-theorysortingenumeration
LeetCode 1948 - Delete Duplicate Folders in System

The problem gives a hierarchical file system represented as a list of absolute paths, where each path is an array of folder names from the root to a leaf folder.

leetcodehardarrayhash-tablestringtriehash-function
CF 262A - Roma and Lucky Numbers

Roma has a collection of positive integers, and he is fascinated with numbers whose decimal digits consist only of 4 and 7. These are called lucky numbers. The task is to determine, from his collection, how many numbers have at most k lucky digits.

codeforcescompetitive-programmingimplementation
LeetCode 3087 - Find Trending Hashtags

The problem asks us to find the top 3 trending hashtags from a table of tweets for a specific month, February 2024. Each tweet contains exactly one hashtag. The input is represented by a Tweets table with columns userid, tweetid, tweet, and tweetdate.

leetcodemediumdatabase
LeetCode 3368 - First Letter Capitalization

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.

leetcodeharddatabase
LeetCode 2920 - Maximum Points After Collecting Coins From All Nodes

We are given a tree with n nodes rooted at node 0. Each node contains a certain number of coins. We must collect coins from every node while respecting the tree hierarchy, meaning a node can only be processed after all of its ancestors have already been processed.

leetcodehardarraydynamic-programmingbit-manipulationtreedepth-first-searchmemoization
LeetCode 3002 - Maximum Size of a Set After Removals

The problem is asking us to maximize the number of unique elements we can have in a set after removing exactly half of the elements from two arrays nums1 and nums2.

leetcodemediumarrayhash-tablegreedy
LeetCode 2546 - Apply Bitwise Operations to Make Strings Equal

The problem provides two binary strings, s and target, of equal length n. You are allowed to perform a specific bitwise operation on s any number of times, which involves picking two distinct indices i and j and updating s[i] to s[i] OR s[j] and s[j] to s[i] XOR s[j].

leetcodemediumstringbit-manipulation
LeetCode 2360 - Longest Cycle in a Graph

This problem gives us a directed graph represented by an array called edges. The graph contains n nodes labeled from 0 to n - 1. Each node has at most one outgoing edge.

leetcodeharddepth-first-searchbreadth-first-searchgraph-theorytopological-sort
LeetCode 2737 - Find the Closest Marked Node

That is a very large, detailed reference document with multiple long sections, full walkthroughs, two language implementations, worked examples, test suites, and edge case analysis for LeetCode 2737.

leetcodemediumarraygraph-theoryheap-(priority-queue)shortest-path
LeetCode 3199 - Count Triplets with Even XOR Set Bits I

The problem gives us three integer arrays, a, b, and c. We must count how many triplets (a[i], b[j], c[k]) produce a bitwise XOR result with an even number of set bits. A set bit is a bit equal to 1 in the binary representation of a number.

leetcodeeasyarraybit-manipulation
LeetCode 2521 - Distinct Prime Factors of Product of Array

The problem asks us to compute the number of distinct prime factors in the product of an array of positive integers, nums.

leetcodemediumarrayhash-tablemathnumber-theory
LeetCode 2307 - Check for Contradictions in Equations

This problem gives us a collection of equations of the form: Each variable is represented as a string, and each equation defines a multiplicative relationship between two variables. The task is to determine whether all equations can simultaneously be true.

leetcodehardarraydepth-first-searchunion-findgraph-theory
CF 444D - DZY Loves Strings

We are given a long string s and a list of pairs of small strings (ai, bi). For each pair, we need to find the shortest substring of s that contains both ai and bi as substrings. If no substring contains both, we report -1.

codeforcescompetitive-programmingbinary-searchhashingstringstwo-pointers
LeetCode 3384 - Team Dominance by Pass Success

This problem asks us to compute a dominance score for each football team across two halves of a match, based on passing outcomes. The input is represented using two database tables, Teams and Passes. The Teams table maps every player to exactly one team.

leetcodeharddatabase
LeetCode 3257 - Maximum Value Sum by Placing Three Rooks II

We are given an m x n matrix called board, where each cell contains an integer value. We must place exactly three rooks on the board. A rook attacks every cell in the same row and the same column.

leetcodehardarraydynamic-programmingmatrixenumeration
CF 239A - Two Bags of Potatoes

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.

codeforcescompetitive-programminggreedyimplementationmath
LeetCode 3186 - Maximum Total Damage With Spell Casting

The problem gives us an array power, where each element represents the damage value of a spell. Every spell can be used at most once, and multiple spells may share the same damage value. The restriction is the important part of the problem.

leetcodemediumarrayhash-tabletwo-pointersbinary-searchdynamic-programmingsortingcounting