brain

tamnd's digital brain — notes, problems, research

42641 notes

LeetCode 3147 - Taking Maximum Energy From the Mystic Dungeon

The problem asks us to maximize the total energy gained from a sequence of magicians arranged in a line, where each magician provides a certain energy value, which can be negative or positive.

leetcodemediumarraydynamic-programmingprefix-sum
LeetCode 1916 - Count Ways to Build Rooms in an Ant Colony

The problem asks us to count the number of valid ways to sequentially build all rooms in an ant colony, given a dependency tree that dictates which rooms must be built before others. Each room i has a predecessor prevRoom[i] that must be built before i.

leetcodehardarraymathdynamic-programmingtreedepth-first-searchgraph-theorytopological-sortcombinatorics
LeetCode 2958 - Length of Longest Subarray With at Most K Frequency

The problem asks us to find the length of the longest contiguous subarray in an array of integers nums such that the frequency of every element in that subarray does not exceed a given integer k. In other words, in the resulting subarray, no number appears more than k times.

leetcodemediumarrayhash-tablesliding-window
CF 250E - Mad Joe

Joe is starting on the top floor of a multi-story building represented as a grid of cells. Each floor is a row of m cells, and each cell can either be empty, contain breakable bricks, or be an unbreakable concrete wall.

codeforcescompetitive-programmingbrute-force
LeetCode 2724 - Sort By

This problem asks us to sort an array using a custom sorting rule. Instead of sorting elements directly by their own value, we are given a function fn that transforms each element into a numeric value, and that numeric value determines the order.

leetcodeeasy
LeetCode 2022 - Convert 1D Array Into 2D Array

The problem asks us to transform a one-dimensional array, original, into a two-dimensional array with m rows and n columns.

leetcodeeasyarraymatrixsimulation
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 3297 - Count Substrings That Can Be Rearranged to Contain a String I

We are given two lowercase strings, word1 and word2. A substring of word1 is considered valid if its characters can be rearranged so that word2 becomes a prefix of the rearranged string. To understand what this means, suppose word2 = "abc".

leetcodemediumhash-tablestringsliding-window
LeetCode 2913 - Subarrays Distinct Element Sum of Squares I

The problem asks us to examine every possible non-empty subarray of the given array nums. For each subarray, we compute how many distinct values appear inside it. After finding this distinct count, we square it and add it to the final answer.

leetcodeeasyarrayhash-table
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 3385 - Minimum Time to Break Locks II

In this problem, Bob must break a collection of locks, where each lock requires a certain minimum amount of energy before it can be destroyed. The input array strength represents these requirements.

leetcodehardarraybreadth-first-searchgraph-theory
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
LeetCode 2372 - Calculate the Influence of Each Salesperson

This problem asks us to calculate the total sales value generated by the customers assigned to each salesperson. We are given three database tables: The Salesperson table contains the list of salespeople. Each salesperson has a unique salespersonid and a name.

leetcodemediumdatabase
LeetCode 2213 - Longest Substring of One Repeating Character

The problem gives us an initial string s and a sequence of update operations. Each update changes exactly one character in the string. After every update, we must determine the length of the longest contiguous substring that contains only one repeating character.

leetcodehardarraystringsegment-treeordered-set
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
LeetCode 2297 - Jump Game VIII

This problem asks us to compute the minimum total cost required to move from index 0 to index n - 1 in an array. The movement rules are unusual because whether a jump is valid depends not only on the values at the start and destination indices, but also on every element in…

leetcodemediumarraydynamic-programmingstackgraph-theorymonotonic-stackshortest-path
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 2732 - Find a Good Subset of the Matrix

The problem asks us to find a subset of rows in a binary matrix where each column’s sum in that subset is at most half of the number of rows chosen, rounded down.

leetcodehardarrayhash-tablebit-manipulationmatrix
LeetCode 3018 - Maximum Number of Removal Queries That Can Be Processed I

The problem asks us to process a sequence of removal queries on an array nums, with an optional initial operation where we can replace nums with any subsequence of itself to optimize query processing. Each query specifies a threshold value.

leetcodehardarraydynamic-programming
CF 252A - Little Xor

We are given a sequence of non-negative integers and we want to pick a contiguous block of elements such that when we take the bitwise XOR of everything inside that block, the result is as large as possible.

codeforcescompetitive-programmingbrute-forceimplementation
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
LeetCode 2391 - Minimum Amount of Time to Collect Garbage

This problem models a garbage collection system with three separate garbage trucks: - One truck collects metal garbage, represented by 'M' - One truck collects paper garbage, represented by 'P' - One truck collects glass garbage, represented by 'G' The input array garbage…

leetcodemediumarraystringprefix-sum
LeetCode 1857 - Largest Color Value in a Directed Graph

The problem asks us to find the largest color value along any path in a directed graph of n nodes, where each node has a color represented by a lowercase English letter. The graph may contain cycles, in which case the function should return -1.

leetcodehardhash-tablestringdynamic-programminggraph-theorytopological-sortmemoizationcounting
LeetCode 2742 - Painting the Walls

The problem is asking us to determine the minimum total cost to paint n walls using two painters with different constraints. We are given two arrays: cost and time, both of size n.

leetcodehardarraydynamic-programming
CF 441A - Valera and Antique Items

Valera wants to buy exactly one antique item from a set of sellers. Each seller offers multiple items with a current auction price. Valera can only secure a deal if he offers strictly more than the current price of an item, and he has a fixed budget v.

codeforcescompetitive-programmingimplementation
LeetCode 3146 - Permutation Difference between Two Strings

The problem asks us to compute the permutation difference between two strings, s and t. Both strings contain unique characters, and t is a permutation of s.

leetcodeeasyhash-tablestring
LeetCode 2147 - Number of Ways to Divide a Long Corridor

The problem presents a long corridor represented as a string, where 'S' denotes a seat and 'P' denotes a plant. The goal is to partition this corridor into sections, such that each section contains exactly two seats and any number of plants.

leetcodehardmathstringdynamic-programming
LeetCode 3342 - Find Minimum Time to Reach Last Room II

This problem describes a dungeon represented as an n x m grid of rooms, where each room has a constraint on the earliest time you can enter it, given by the 2D array moveTime.

leetcodemediumarraygraph-theoryheap-(priority-queue)matrixshortest-path
CF 238C - World Eater Brothers

We are given a world of n countries connected by n-1 directed roads. Ignoring the direction of these roads, the countries form a tree. Each brother wants to establish rule in some country and can control every country reachable via directed roads.

codeforcescompetitive-programmingdfs-and-similardpgreedytrees
LeetCode 1922 - Count Good Numbers

The problem asks us to count how many digit strings of length n satisfy a specific positional rule. A digit string is considered "good" when: - Every digit placed at an even index, meaning indices 0, 2, 4, ..., must itself be an even digit.

leetcodemediummathrecursion
CF 231C - To Add or Not to Add

We are given an array of integers and a limited number of increment operations. Each operation increases a single element by one, and the same element can be increased multiple times.

codeforcescompetitive-programmingbinary-searchsortingstwo-pointers
CF 205A - Little Elephant and Rozdil

We are given a list of travel times from the town Rozdil to each of n other towns. Each town has a positive integer time, and the towns are numbered from 1 to n. The goal is to find which town has the smallest travel time.

codeforcescompetitive-programmingbrute-forceimplementation
LeetCode 3364 - Minimum Positive Sum Subarray

The problem asks us to find the smallest positive sum among all subarrays whose lengths fall within a given range [l, r]. A subarray is a contiguous section of the array. We are allowed to choose any non-empty contiguous segment as long as: 1.

leetcodeeasyarraysliding-windowprefix-sum
LeetCode 3131 - Find the Integer Added to Array I

The problem gives us two integer arrays, nums1 and nums2, which have the same length. We are told that every element in nums1 was modified by adding the same integer x, and after this transformation the resulting array became equal to nums2.

leetcodeeasyarray
LeetCode 2345 - Finding the Number of Visible Mountains

Each mountain is represented by a peak point (x, y). Because the mountain is a right-angled isosceles triangle with slopes +1 and -1, its shape is completely determined by its peak.

leetcodemediumarraystacksortingmonotonic-stack
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 3231 - Minimum Number of Increasing Subsequence to Be Removed

We are given an integer array nums. In one operation, we may choose any subsequence of the array that is strictly increasing and remove all of its elements simultaneously. A subsequence does not need to be contiguous. We only need to preserve the relative order of elements.

leetcodehardarraybinary-search
LeetCode 2189 - Number of Ways to Build House of Cards

The problem is asking us to count the number of distinct ways to build a house of cards using exactly n cards. Each house consists of one or more rows of triangles formed by leaning two cards together, with horizontal cards placed between adjacent triangles.

leetcodemediummathdynamic-programming
LeetCode 2445 - Number of Nodes With Value One

The tree in this problem is not given explicitly through an edge list. Instead, the structure is defined mathematically. Every node v has parent floor(v / 2), which creates the same structure as a binary heap.

leetcodemediumarraytreedepth-first-searchbreadth-first-searchbinary-tree
CF 421A - Pasha and Hamsters

We are given a line of apples numbered from 1 to n. Each apple can be given to exactly one of two hamsters, Arthur or Alexander. The only restriction is that Arthur must receive only apples he likes, and Alexander must receive only apples he likes.

codeforcescompetitive-programmingconstructive-algorithmsimplementation
LeetCode 2155 - All Divisions With the Highest Score of a Binary Array

The problem gives us a binary array nums, meaning every element is either 0 or 1. We are allowed to divide the array at any index i where 0 <= i <= n, and that division creates two parts: - The left part contains elements from index 0 to i - 1 - The right part contains…

leetcodemediumarray
LeetCode 2326 - Spiral Matrix IV

The problem gives us a linked list and asks us to place its values into an m x n matrix in clockwise spiral order. We begin filling from the top-left corner of the matrix, which is position (0, 0). The traversal direction follows the standard spiral pattern: 1.

leetcodemediumarraylinked-listmatrixsimulation
LeetCode 3120 - Count the Number of Special Characters I

The problem asks us to count the number of special characters in a given string word. A character is defined as special if it appears in both lowercase and uppercase forms within the same string.

leetcodeeasyhash-tablestring
LeetCode 3247 - Number of Subsequences with Odd Sum

The problem asks us to count how many subsequences of the given array have an odd sum. A subsequence is formed by choosing any subset of elements while preserving their original order. Unlike subarrays, subsequences do not need to be contiguous.

leetcodemediumarraymathdynamic-programmingcombinatorics
LeetCode 3150 - Invalid Tweets II

The problem gives us a database table named Tweets with two columns: | Column | Description | | --- | --- | | tweetid | Unique identifier for each tweet | | content | The text content of the tweet | We need to identify all tweets that are considered invalid.

leetcodeeasydatabase
CF 305E - Playing with String

We are asked to analyze a two-player string game. Players alternate moves. On a turn, a player can select any string fragment available (initially the whole string) and cut a character that is the center of a palindrome of odd length.

codeforcescompetitive-programminggames
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 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
LeetCode 1955 - Count Number of Special Subsequences

This problem asks us to count the number of special subsequences in an array nums that consists only of integers 0, 1, and 2. A subsequence is special if it follows the pattern of one or more 0s, followed by one or more 1s, followed by one or more 2s.

leetcodehardarraydynamic-programming
LeetCode 3396 - Minimum Number of Operations to Make Elements in Array Distinct

The problem gives us an integer array nums, and our goal is to make all remaining elements distinct. The only allowed operation is removing exactly 3 elements from the beginning of the array. If fewer than 3 elements remain, we remove everything that is left.

leetcodeeasyarrayhash-table
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 244B - Undoubtedly Lucky Numbers

We are given a single positive integer $n$, and we need to count how many integers from 1 up to $n$ have a very specific property: there exists a pair of digits $x$ and $y$ such that every digit in the number’s decimal representation is either $x$ or $y$.

codeforcescompetitive-programmingbitmasksbrute-forcedfs-and-similar
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 302A - Eugeny and Array

We are given an array containing only 1 and -1. For every query [l, r], we look at the subarray from index l to r.

codeforcescompetitive-programmingimplementation
LeetCode 3395 - Subsequences with a Unique Middle Mode I

We are given an integer array nums, and we must count how many subsequences of length 5 satisfy a very specific condition: - The subsequence must have exactly 5 elements.

leetcodehardarrayhash-tablemathcombinatorics
LeetCode 3042 - Count Prefix and Suffix Pairs I

The problem gives us an array of strings called words. For every pair of indices (i, j) where i < j, we must determine whether words[i] is both a prefix and a suffix of words[j]. A string is a prefix of another string if it appears at the beginning.

leetcodeeasyarraystringtrierolling-hashstring-matchinghash-function
LeetCode 2061 - Number of Spaces Cleaning Robot Cleaned

In this problem, we are given a 2D binary matrix called room. Each cell represents a position in the room: - 0 means the space is empty and can be cleaned. - 1 means the space contains an object and cannot be entered.

leetcodemediumarraymatrixsimulation
LeetCode 3174 - Clear Digits

In this problem, we are given a string s that contains lowercase English letters and digits. The task is to repeatedly remove digits according to a very specific rule. Whenever we encounter a digit, we must delete two characters: 1. The digit itself 2.

leetcodeeasystringstacksimulation
LeetCode 2679 - Sum in a Matrix

The problem gives us a 2D integer matrix nums. Each row contains several integers, and we repeatedly perform a special removal process until every element has been removed. During each operation, we do two things: 1. From every row, remove the largest remaining element. 2.

leetcodemediumarraysortingheap-(priority-queue)matrixsimulation
LeetCode 2409 - Count Days Spent Together

The problem asks us to calculate the number of days Alice and Bob spend together in Rome based on their respective arrival and departure dates. Each date is represented as a string in the format "MM-DD".

leetcodeeasymathstring
LeetCode 1973 - Count Nodes Equal to Sum of Descendants

This problem asks us to analyze a binary tree and count how many nodes satisfy a specific property: the value of the node equals the sum of all its descendants. A descendant of a node is any node that lies in the subtree rooted at that node excluding the node itself.

leetcodemediumtreedepth-first-searchbinary-tree
LeetCode 2704 - To Be Or Not To Be

This problem asks us to implement a very small testing utility that mimics the behavior of assertion libraries used in real software development. We need to create a function named expect that accepts any value and returns an object containing two methods: toBe and notToBe.

leetcodeeasy
LeetCode 3073 - Maximum Increasing Triplet Value

We are given an integer array nums, and we must find three indices (i, j, k) such that: - i < j < k - nums[i] < nums[j] < nums[k] Among all valid increasing triplets, we want to maximize the expression: The task is not to maximize the sum of the triplet.

leetcodemediumarrayordered-set
LeetCode 2343 - Query Kth Smallest Trimmed Number

This problem provides a list of numbers represented as strings, all of equal length. The task is to answer multiple queries, where each query asks for the index of the k-th smallest number after trimming every number in the list to its last trimi digits.

leetcodemediumarraystringdivide-and-conquersortingheap-(priority-queue)radix-sortquickselect
LeetCode 2893 - Calculate Orders Within Each Interval

The problem asks us to process an Orders table where each row contains a minute and the number of orders received during that specific minute. We are tasked with calculating the total number of orders in intervals of six consecutive minutes.

leetcodemediumdatabase
LeetCode 3346 - Maximum Frequency of an Element After Performing Operations I

The problem gives us an integer array nums, along with two integers, k and numOperations. We are allowed to perform exactly numOperations operations.

leetcodemediumarraybinary-searchsliding-windowsortingprefix-sum
CF 265A - Colorful Stones (Simplified Edition)

The problem describes a row of stones, each colored red, green, or blue, represented by a string s of characters 'R', 'G', and 'B'. Squirrel Liss starts on the first stone and executes a sequence of color-based instructions, given by a second string t.

codeforcescompetitive-programmingimplementation
LeetCode 3179 - Find the N-th Value After K Seconds

The problem requires computing the value of the last element in an array after a series of sequential cumulative sum operations over a fixed number of seconds. You start with an array a of length n where all elements are initialized to 1.

leetcodemediumarraymathsimulationcombinatoricsprefix-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 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
CF 191B - Demonstration

We are asked to determine the earliest square where the opposition can hold a demonstration given the interference of the city administration. There are n squares arranged by increasing distance from the city center, with square 1 being the most central.

codeforcescompetitive-programminggreedy
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)
CF 415A - Mashmokh and Lights

The factory has a row of lights indexed from left to right. Every light starts in the “on” state. Mashmokh performs a sequence of button presses, and each button has an index that determines how far to the right its effect extends.

codeforcescompetitive-programmingimplementation
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 138E - Hellish Constraints

We are asked to count substrings of a given string that satisfy a complicated set of constraints. Each constraint specifies a letter and a minimum and maximum number of times that letter can appear.

codeforcescompetitive-programmingbrute-forcedptwo-pointers
LeetCode 2673 - Make Costs of Paths Equal in a Binary Tree

Edit This problem gives us a perfect binary tree with n nodes, where each node has an associated cost. The tree follows a strict indexing rule: node i has a left child at 2 i and a right child at 2 i + 1.

leetcodemediumarraydynamic-programminggreedytreebinary-tree
LeetCode 2616 - Minimize the Maximum Difference of Pairs

The problem asks us to select exactly p disjoint pairs from the array nums such that the largest difference among all chosen pairs is as small as possible.

leetcodemediumarraybinary-searchdynamic-programminggreedysorting
CF 212C - Cowboys

We are given a circular arrangement of cows, each cow facing exactly one of its two neighbors. Represent the circle as a binary string where each character describes direction: one symbol means “point to clockwise neighbor” and the other means “point to counterclockwise…

codeforcescompetitive-programmingcombinatoricsdpmath
LeetCode 2782 - Number of Unique Categories

This problem asks us to determine how many distinct categories exist among n elements. The elements are labeled from 0 to n - 1, but we are not given the category values directly.

leetcodemediumunion-findinteractivecounting
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
LeetCode 3050 - Pizza Toppings Cost Analysis

This problem asks us to compute the total cost of all possible three-topping pizza combinations using a list of available toppings from a database table. Each topping has a name and a cost, and toppings are unique.

leetcodemediumdatabase
LeetCode 2986 - Find Third Transaction

The problem gives us a Transactions table that stores three pieces of information for every transaction: - userid, which identifies the user - spend, which represents the transaction amount - transactiondate, which represents when the transaction occurred The pair (userid…

leetcodemediumdatabase
LeetCode 2612 - Minimum Reverse Operations

This will be a very large, multi-thousand-word technical guide because of the required depth, full proofs, worked examples, Python and Go implementations, detailed walkthroughs, complexity reasoning, and exhaustive tests.

leetcodehardarrayhash-tablebreadth-first-searchunion-findordered-set
LeetCode 2549 - Count Distinct Numbers on Board

The problem starts with a single integer n written on a board. Every day, we examine every number currently on the board. For each number x, we look for all integers i such that: - 1 <= i <= n - x % i == 1 Whenever such an integer i exists, we add it to the board.

leetcodeeasyarrayhash-tablemathsimulation
LeetCode 2669 - Count Artist Occurrences On Spotify Ranking List

This problem provides a database table named Spotify that contains information about songs appearing in a Spotify ranking list.

leetcodeeasydatabase
CF 255D - Mr. Bender and Square

We are asked to simulate the spread of a signal across an n × n grid. Initially, a single cell at row x and column y is turned on, and in each second, any cell that is side-adjacent to a turned-on cell also turns on.

codeforcescompetitive-programmingbinary-searchimplementationmath
LeetCode 1934 - Confirmation Rate

This problem asks us to calculate the confirmation rate for each user in a system where users can request confirmation messages after signing up. We are given two tables: Signups and Confirmations.

leetcodemediumdatabase
CF 173D - Deputies

We are asked to assign k deputies to n cities, with the condition that each deputy manages exactly three cities. The cities are placed on two sides of a river, and some pairs of cities are connected by bridges that span the river.

codeforcescompetitive-programmingconstructive-algorithmsgraphsgreedyimplementation
LeetCode 3273 - Minimum Amount of Damage Dealt to Bob

This problem asks us to determine the minimum total damage Bob will receive while fighting a group of enemies. Each enemy has two attributes: - damage[i], the amount of damage they inflict on Bob every second while alive. - health[i], the amount of health they start with.

leetcodehardarraygreedysorting
CF 354E - Lucky Number Representation

The problem asks us to express each of a set of positive integers as a sum of exactly six numbers that only contain the digits 0, 4, or 7. These “lucky” numbers include zero, so numbers like 0, 4, 40, 47, 400, or 7074 are all valid.

codeforcescompetitive-programmingconstructive-algorithmsdfs-and-similardp
LeetCode 2290 - Minimum Obstacle Removal to Reach Corner

This problem gives us a 2D grid where every cell is either empty or blocked by an obstacle. A value of 0 means we can move through the cell freely, while a value of 1 means the cell contains an obstacle that can be removed.

leetcodehardarraybreadth-first-searchgraph-theoryheap-(priority-queue)matrixshortest-path
CF 415B - Mashmokh and Tokens

Each day Mashmokh receives a pile of tokens, and at the end of that day he can exchange some of them for money using a fixed conversion rule.

codeforcescompetitive-programmingbinary-searchgreedyimplementationmath
LeetCode 3085 - Minimum Deletions to Make String K-Special

The problem asks us to transform a given string word into a k-special string using the minimum number of deletions. A string is considered k-special if, for every pair of characters in the string, the difference in their frequencies does not exceed k.

leetcodemediumhash-tablestringgreedysortingcounting
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 226B - Naughty Stone Piles

We have several stone piles, each with some initial size. One operation chooses a source pile and merges it into another pile. The source pile disappears, the destination pile grows, and the operation cost equals the current size of the source pile.

codeforcescompetitive-programminggreedy
LeetCode 2200 - Find All K-Distant Indices in an Array

The problem requires identifying all indices in an array nums that are "k-distant" from at least one occurrence of a given value key.

leetcodeeasyarraytwo-pointers
LeetCode 3031 - Minimum Time to Revert Word to Initial State II

The problem requires simulating a repetitive transformation on a string word where, at each second, the first k characters are removed, and then any k characters are appended to the end.

leetcodehardstringrolling-hashstring-matchinghash-function
LeetCode 2552 - Count Increasing Quadruplets

The problem asks us to count the number of increasing quadruplets (i, j, k, l) in a 0-indexed array nums of size n, where nums is a permutation of the integers from 1 to n.

leetcodehardarraydynamic-programmingbinary-indexed-treeenumerationprefix-sum
LeetCode 2400 - Number of Ways to Reach a Position After Exactly k Steps

This problem asks us to count the number of distinct ways to move from startPos to endPos on an infinite number line using exactly k steps. At each step, we may move either one position to the left (-1) or one position to the right (+1).

leetcodemediummathdynamic-programmingcombinatorics
CF 420E - Playing the ball

A ball is thrown from the origin along some chosen direction, and it repeatedly appears at equally spaced points along that ray: first at distance $d$, then at $2d$, then $3d$, and so on. The direction is fixed once chosen, but it can be any real direction in the plane.

codeforcescompetitive-programminggeometry