brain

tamnd's digital brain — notes, problems, research

43815 notes

LeetCode 3303 - Find the Occurrence of First Almost Equal Substring

We are given two strings, s and pattern. The task is to find the smallest starting index in s such that the substring of length len(pattern) is "almost equal" to pattern.

leetcodehardstringstring-matching
LeetCode 1935 - Maximum Number of Words You Can Type

The problem is asking us to determine how many words in a given string can be fully typed on a malfunctioning keyboard. The keyboard has some broken letter keys that cannot be used.

leetcodeeasyhash-tablestring
LeetCode 2167 - Minimum Time to Remove All Cars Containing Illegal Goods

The problem presents a binary string s representing a sequence of train cars. Each character '0' or '1' denotes whether a train car contains illegal goods ('1') or not ('0').

leetcodehardstringdynamic-programming
LeetCode 1886 - Determine Whether Matrix Can Be Obtained By Rotation

The problem gives us two square binary matrices, mat and target, both of size n x n. Each cell contains either 0 or 1. Our task is to determine whether mat can be transformed into target by rotating it clockwise in 90 degree increments. A rotation can be performed multiple times.

leetcodeeasyarraymatrix
CF 155B - Combination

We have a collection of cards. Every card gives two things when played. The first number adds to the score, and the second number adds extra opportunities to play more cards. The game starts with exactly one available move.

codeforcescompetitive-programminggreedysortings
LeetCode 2174 - Remove All Ones With Row and Column Flips II

The problem gives us an m x n binary matrix where every cell contains either 0 or 1. Our goal is to remove all 1s using the minimum number of operations. An operation can only be performed on a cell (i, j) that currently contains a 1.

leetcodemediumarraybit-manipulationbreadth-first-searchmatrix
LeetCode 3340 - Check Balanced String

The problem gives us a string num that contains only numeric digits from '0' to '9'. We must determine whether the string is "balanced". A string is considered balanced when the sum of digits located at even indices is equal to the sum of digits located at odd indices.

leetcodeeasystring
LeetCode 2526 - Find Consecutive Integers from a Data Stream

The problem asks us to design a data structure that continuously processes a stream of integers and determines whether the most recent k integers are all equal to a specific target value.

leetcodemediumhash-tabledesignqueuecountingdata-stream
LeetCode 2684 - Maximum Number of Moves in a Grid

The problem gives us an m x n matrix called grid, where every cell contains a positive integer. We may begin from any row in the first column, meaning any cell (row, 0) is a valid starting point.

leetcodemediumarraydynamic-programmingmatrix
LeetCode 2741 - Special Permutations

The problem asks us to count the number of special permutations of a given array of distinct positive integers nums.

leetcodemediumarraydynamic-programmingbit-manipulationbitmask
LeetCode 2937 - Make Three Strings Equal

The problem asks us to make three strings s1, s2, and s3 identical by repeatedly deleting their rightmost characters. Each deletion is counted as one operation. The key restriction is that we cannot completely delete a string, so at least one character must remain in each string.

leetcodeeasystring
LeetCode 3065 - Minimum Operations to Exceed Threshold Value I

The problem asks us to find the minimum number of operations needed to ensure that every element in an array is at least k. Each operation consists of removing the smallest element from the array.

leetcodeeasyarray
CF 183D - T-shirt

We are tasked with distributing T-shirts to a line of engineers where each engineer has a probability distribution over which T-shirt size fits them. We know how many engineers, n, there are, and the total number of T-shirt sizes, m.

codeforcescompetitive-programmingdpgreedyprobabilities
LeetCode 2914 - Minimum Number of Changes to Make Binary String Beautiful

You are given a binary string s whose length is guaranteed to be even. A binary string contains only the characters '0' and '1'. A string is considered beautiful if it can be divided into one or more contiguous substrings such that: - Every substring has even length.

leetcodemediumstring
CF 238D - Tape Programming

We are given a sequence of characters consisting of digits 0-9 and the symbols < and . This sequence is interpreted as a simple tape program. The interpreter has two pointers: the current character pointer (CP) and the direction pointer (DP).

codeforcescompetitive-programmingdata-structuresimplementation
LeetCode 2356 - Number of Unique Subjects Taught by Each Teacher

The problem requires calculating the number of unique subjects each teacher teaches in a university, given a table that maps teachers to subjects and departments. Each row in the Teacher table represents a specific combination of a teacher, a subject, and a department.

leetcodeeasydatabase
LeetCode 2796 - Repeat String

This problem asks us to extend the behavior of strings so that every string supports a replicate(x) method. The method should return a new string where the original string is repeated exactly x times.

leetcodeeasy
LeetCode 2195 - Append K Integers With Minimal Sum

The problem asks us to append k unique positive integers to an existing array nums such that none of the integers we add are already in nums, and the sum of the numbers we append is minimized.

leetcodemediumarraymathgreedysorting
CF 427D - Match & Catch

We are given two lowercase strings. From each string we can look at every contiguous segment, and we care about those segments that behave unusually: a segment is considered special if it appears exactly once in its own string.

codeforcescompetitive-programmingdpstring-suffix-structuresstrings
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
CF 214B - Hometask

We are given a multiset of digits and asked to construct the largest integer from some or all of them such that the resulting number is divisible by 2, 3, and 5 simultaneously.

codeforcescompetitive-programmingbrute-forceconstructive-algorithmsgreedymath
LeetCode 2323 - Find Minimum Time to Finish All Jobs II

This problem asks us to assign jobs to workers in a way that minimizes the total number of days needed to finish all jobs. We are given two integer arrays of equal length: - jobs[i] represents the amount of work required for the i-th job.

leetcodemediumarraygreedysorting
LeetCode 2493 - Divide Nodes Into the Maximum Number of Groups

We are given an undirected graph with n nodes and a list of edges. The graph may contain multiple disconnected components. Our task is to divide all nodes into ordered groups numbered from 1 to m. The key constraint is based on graph edges.

leetcodeharddepth-first-searchbreadth-first-searchunion-findgraph-theory
CF 256E - Lucky Arrays

We are given an array of length n, initially filled with zeroes. Each query sets a single element to a value between 0 and 3. Zero represents an unset element, while 1, 2, or 3 are actual values.

codeforcescompetitive-programmingdata-structures
LeetCode 3110 - Score of a String

This problem asks us to compute the score of a string, where the score is defined as the sum of the absolute differences of ASCII values of consecutive characters in the string.

leetcodeeasystring
LeetCode 2506 - Count Pairs Of Similar Strings

The problem gives us an array of strings called words. We must count how many pairs of indices (i, j) satisfy two conditions: - i < j - words[i] and words[j] are similar Two strings are considered similar if they contain exactly the same set of distinct characters, regardless…

leetcodeeasyarrayhash-tablestringbit-manipulationcounting
LeetCode 2640 - Find the Score of All Prefixes of an Array

The problem requires calculating a score for all prefixes of an array. Given an integer array nums, we first define a conversion array for any prefix of nums.

leetcodemediumarrayprefix-sum
LeetCode 2284 - Sender With Largest Word Count

The problem asks us to analyze a chat log containing n messages and identify which sender has written the most words overall. Each message is represented as a string in the messages array, and the corresponding sender of that message is at the same index in the senders array.

leetcodemediumarrayhash-tablestringcounting
LeetCode 2898 - Maximum Linear Stock Score

We are given a 1-indexed array prices, where prices[i] represents the stock price on day i. We want to choose a subsequence of indices, not necessarily contiguous, such that the selected indices satisfy a special linearity condition.

leetcodemediumarrayhash-table
LeetCode 2621 - Sleep

The problem asks us to implement an asynchronous function sleep that pauses execution for a given number of milliseconds, specified by the input millis.

leetcodeeasy
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
LeetCode 3078 - Match Alphanumerical Pattern in Matrix I

This problem asks us to search for a rectangular submatrix inside a larger integer matrix, where the submatrix follows a pattern described by digits and lowercase letters.

leetcodemediumarrayhash-tablestringmatrix
CF 270B - Multithreading

The forum keeps a list of threads ordered by the time of their latest message. Whenever someone posts in a thread, that thread immediately moves to the front of the list. No other reordering happens. Initially the threads are ordered as 1, 2, 3, ..., n.

codeforcescompetitive-programmingdata-structuresgreedyimplementation
LeetCode 3287 - Find the Maximum Sequence Value of Array

We are given an array nums and an integer k. We must choose a subsequence of exactly 2 k elements while preserving the original order of the array. After selecting the subsequence, we split it into two equal halves: - The first k selected elements form the left group.

leetcodehardarraydynamic-programmingbit-manipulation
CF 229C - Triangles

We start with a complete undirected graph on n vertices. Every pair of vertices has exactly one edge between them. Alice keeps m of those edges, and Bob receives all remaining edges.

codeforcescompetitive-programmingcombinatoricsgraphsmath
LeetCode 3203 - Find Minimum Diameter After Merging Two Trees

We are given two separate undirected trees. The first tree contains n nodes and is represented by edges1, while the second tree contains m nodes and is represented by edges2. A tree is a connected graph with no cycles.

leetcodehardtreedepth-first-searchbreadth-first-searchgraph-theory
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 3317 - Find the Number of Possible Ways for an Event

The problem describes an event with n performers and x available stages. Each performer must be assigned to exactly one stage. Multiple performers may share the same stage, which means they form a band together. Some stages may remain unused.

leetcodehardmathdynamic-programmingcombinatorics
LeetCode 2304 - Minimum Path Cost in a Grid

The problem gives us a matrix called grid with m rows and n columns. Every cell contains a unique integer from 0 to m n - 1. We may start from any cell in the first row and move downward one row at a time until we reach the last row. The movement rule is very flexible.

leetcodemediumarraydynamic-programmingmatrix
LeetCode 2859 - Sum of Values at Indices With K Set Bits

The problem asks us to compute the sum of elements in an array, but not based on the values themselves. Instead, we decide whether to include an element by examining the binary representation of its index. You are given a 0-indexed integer array nums and an integer k.

leetcodeeasyarraybit-manipulation
LeetCode 2068 - Check Whether Two Strings are Almost Equivalent

The problem asks us to determine whether two strings are "almost equivalent" based on the frequency of each lowercase English letter. We are given two strings, word1 and word2, both of the same length.

leetcodeeasyhash-tablestringcounting
LeetCode 3181 - Maximum Total Reward Using Operations II

The problem gives us an array rewardValues, where each element represents a reward we may choose exactly once. We begin with a total reward x = 0, and we are allowed to repeatedly pick an unmarked element only if its value is strictly greater than the current total reward.

leetcodehardarraydynamic-programmingbit-manipulation
LeetCode 3338 - Second Highest Salary II

This problem asks us to analyze employee salary data within departments and extract all employees earning the second-highest salary in each department. The input is a table employees with three columns: empid, salary, and dept.

leetcodemediumdatabase
LeetCode 2302 - Count Subarrays With Score Less Than K

The problem asks us to count the number of contiguous subarrays of a given array nums whose score is strictly less than a given threshold k. The score of a subarray is defined as the product of its sum and its length.

leetcodehardarraybinary-searchsliding-windowprefix-sum
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 255E - Furlo and Rublo and Game

We have several independent piles of coins. A move picks one pile with size x and replaces it with some smaller value y such that $$x^{1/4} le y le x^{1/2}$$ and y < x. The player who cannot make a move loses.

codeforcescompetitive-programminggamesimplementationmath
LeetCode 1966 - Binary Searchable Numbers in an Unsorted Array

This problem asks us to identify how many numbers in an unsorted array are still guaranteed to be found by a randomized binary-search-like process. The array nums contains unique integers.

leetcodemediumarraybinary-searchstackmonotonic-stack
CF 183C - Cyclic Coloring

We have a directed graph where every edge enforces a strict relationship between the colors of its endpoints. If a vertex has color c, then every outgoing neighbor must have color c + 1, wrapping around modulo k.

codeforcescompetitive-programmingdfs-and-similar
CF 199B - Special Olympics

We are asked to count the number of distinct circular contours that can be formed on a plane where two black-painted rings are placed. Each ring is defined by two concentric circles, an inner radius and an outer radius.

codeforcescompetitive-programminggeometry
LeetCode 2712 - Minimum Cost to Make All Characters Equal

The problem gives us a binary string s consisting only of characters '0' and '1'. Our goal is to make every character in the string equal, meaning the final string must become either all '0' characters or all '1' characters. We are allowed to perform two types of operations: 1.

leetcodemediumstringdynamic-programminggreedy
LeetCode 3354 - Make Array Elements Equal to Zero

The problem gives us an integer array nums, where some elements may already be zero and others are positive integers. We must choose a starting index curr such that nums[curr] == 0, and also choose an initial movement direction, either left or right.

leetcodeeasyarraysimulationprefix-sum
LeetCode 2444 - Count Subarrays With Fixed Bounds

This problem asks us to count how many contiguous subarrays satisfy two exact boundary conditions at the same time: 1. The minimum element in the subarray must be exactly minK. 2. The maximum element in the subarray must be exactly maxK.

leetcodehardarrayqueuesliding-windowmonotonic-queue
CF 302B - Eugeny and Play List

The playlist is built from blocks of repeated songs. Song i has duration t[i], and Eugeny listens to it c[i] times consecutively before moving to the next song. If a song lasts 4 minutes and is repeated 3 times, that block contributes 12 minutes to the playlist timeline.

codeforcescompetitive-programmingbinary-searchimplementationtwo-pointers
LeetCode 2499 - Minimum Total Cost to Make Arrays Unequal

You are given two arrays, nums1 and nums2, both of length n. You are allowed to perform operations only on nums1. In a single operation, you may swap any two indices in nums1, and the cost of that operation is the sum of the two indices involved in the swap.

leetcodehardarrayhash-tablegreedycounting
CF 426A - Sereja and Mugs

We have a cup with capacity s and several mugs containing water. Players take turns choosing one non-empty mug and pouring all of its water into the cup. The cup starts empty and water is never removed.

codeforcescompetitive-programmingimplementation
CF 142A - Help Farmer

After the theft, the barn contains a smaller rectangular box of hay blocks. If the original dimensions were $A times B times C$, then the remaining pile has dimensions $(A-1) times (B-2) times (C-2)$.

codeforcescompetitive-programmingbrute-forcemath
CF 263E - Rhombus

We are given a rectangular grid of non-negative integers. For every valid center cell (x, y), we define a diamond-shaped region of radius k - 1. The function f(x, y) is the sum of all values inside that rhombus. The task is not to compute every value explicitly and print them.

codeforcescompetitive-programmingbrute-forcedata-structuresdp
LeetCode 3225 - Maximum Score From Grid Operations

This problem presents a 2D square matrix grid of size n x n where each cell contains a non-negative integer. Initially, all cells are white. An operation consists of selecting a cell (i, j) and coloring black all cells in column j from the top (row 0) down to row i.

leetcodehardarraydynamic-programmingmatrixprefix-sum
LeetCode 2785 - Sort Vowels in a String

This problem requires us to reorder the vowels in a string while keeping all consonants in their original positions.

leetcodemediumstringsorting
CF 149A - Business trip

Petya can decide in which months he waters the flower. Each month contributes a fixed amount of growth, and skipping a month contributes nothing. The goal is to reach at least k centimeters of total growth while using as few months as possible.

codeforcescompetitive-programminggreedyimplementationsortings
LeetCode 2178 - Maximum Split of Positive Even Integers

The problem is asking us to take an input integer finalSum and split it into the maximum number of unique positive even integers such that their sum equals finalSum.

leetcodemediummathbacktrackinggreedy
LeetCode 3337 - Total Characters in String After Transformations II

The problem defines a repeated string transformation process over lowercase English letters. Every character does not simply become one new character, instead it expands into multiple characters depending on the value stored in nums.

leetcodehardhash-tablemathstringdynamic-programmingcounting
CF 420C - Bug in Code

Each participant in the company meeting points to two other people and claims that the culprit is one of those two. From this we can think of the input as an array of length $n$, where each index $i$ stores an unordered pair $(xi, yi)$.

codeforcescompetitive-programmingdata-structuresgraphsimplementationtwo-pointers
LeetCode 3011 - Find if Array Can Be Sorted

Here’s the complete, detailed technical solution guide for LeetCode 3011 - Find if Array Can Be Sorted, following your requested formatting and style: The problem provides a 0-indexed array of positive integers nums.

leetcodemediumarraybit-manipulationsorting
CF 213C - Relay Race

We are given an n×n grid where each cell contains an integer, which can be positive or negative. Furik starts at the top-left corner (1,1) and moves only right or down, while Rubik starts at the bottom-right corner (n,n) and moves only left or up.

codeforcescompetitive-programmingdp
LeetCode 3228 - Maximum Number of Operations to Move Ones to the End

The problem gives us a binary string s, consisting only of characters '0' and '1'. We are allowed to repeatedly perform a specific operation: - Find an index i such that: - s[i] == '1' - s[i + 1] == '0' - Move that '1' to the right until it either: - reaches the end of the…

leetcodemediumstringgreedycounting
LeetCode 3141 - Maximum Hamming Distances

The problem asks us to compute the maximum Hamming distance for each element in an array of integers. The Hamming distance between two integers is defined as the number of positions where their binary representations differ.

leetcodehardarraybit-manipulationbreadth-first-search
LeetCode 2160 - Minimum Sum of Four Digit Number After Splitting Digits

The problem asks us to take a four-digit integer num and split its digits into two new integers such that the sum of these two integers is minimized. We are allowed to use all digits exactly once, and the new integers can have leading zeros.

leetcodeeasymathgreedysorting
LeetCode 2104 - Sum of Subarray Ranges

The problem gives us an integer array nums, and asks us to compute the sum of the ranges of every possible non-empty contiguous subarray. The range of a subarray is defined as: For every possible subarray, we calculate its range, then add all of those ranges together.

leetcodemediumarraystackmonotonic-stack
LeetCode 2076 - Process Restricted Friend Requests

This problem models a social network with friendship restrictions. We are given n people labeled from 0 to n - 1. Initially, nobody is connected to anyone else. Over time, friendship requests arrive one by one, and each request must be processed immediately.

leetcodehardunion-findgraph-theory
CF 218A - Mountain Scenery

We are given a polyline representing mountain peaks. The polyline has 2n + 1 vertices, with even-indexed vertices (2, 4, 6, ..., 2n) representing peaks. In the initial picture, each peak is strictly higher than its neighbors, i.e., for every even i, y[i-1] < y[i] y[i+1].

codeforcescompetitive-programmingbrute-forceconstructive-algorithmsimplementation
LeetCode 2711 - Difference of Number of Distinct Values on Diagonals

The problem is asking us to compute a new matrix answer based on a given m x n grid, where each cell in answer represents the absolute difference between the number of distinct elements on the diagonal above and to the left of the current cell, and the number of distinct…

leetcodemediumarrayhash-tablematrix
CF 164D - Minimum Diameter

We are given up to 1000 points on the plane, and we must remove exactly k of them. After removing those points, the remaining set should have the smallest possible diameter. The diameter of a set is the maximum Euclidean distance between any two remaining points.

codeforcescompetitive-programmingbinary-searchbrute-force
CF 177A2 - Good Matrix Elements

We are given a square matrix of size n×n, where n is guaranteed to be odd. Each cell of the matrix contains a non-negative integer. The task is to sum the "good" elements of this matrix.

codeforcescompetitive-programmingimplementation
LeetCode 2169 - Count Operations to Obtain Zero

The problem asks us to count the number of operations required to reduce either of two non-negative integers num1 or num2 to zero. An operation is defined as subtracting the smaller number from the larger one (or subtracting either if they are equal).

leetcodeeasymathsimulation
LeetCode 2350 - Shortest Impossible Sequence of Rolls

Here is a complete, detailed technical solution guide for LeetCode 2350 - Shortest Impossible Sequence of Rolls, following your requested format precisely.

leetcodehardarrayhash-tablegreedy
LeetCode 2818 - Apply Operations to Maximize Score

The problem gives us an array nums and an integer k. We begin with a score of 1, and we are allowed to perform at most k operations. In each operation, we choose a subarray that has not been chosen before. From that subarray, we select the element with the highest prime score.

leetcodehardarraymathstackgreedysortingmonotonic-stacknumber-theory
CF 162B - Binary notation

We are given a single positive integer and must print its representation in base 2. In other words, instead of expressing the number as powers of 10, we express it as powers of 2 using only digits 0 and 1.

codeforcescompetitive-programming*special
LeetCode 3341 - Find Minimum Time to Reach Last Room I

The problem is asking for the minimum time required to reach the bottom-right room (n - 1, m - 1) in a dungeon represented as an n x m grid. Each room (i, j) has a moveTime[i][j], which specifies the earliest time at which the room can be entered.

leetcodemediumarraygraph-theoryheap-(priority-queue)matrixshortest-path
LeetCode 1864 - Minimum Number of Swaps to Make the Binary String Alternating

The problem gives us a binary string s that contains only '0' and '1'. We are allowed to swap any two characters in the string, not necessarily adjacent ones. Our goal is to transform the string into an alternating binary string using the minimum number of swaps.

leetcodemediumstringgreedy
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
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 2477 - Minimum Fuel Cost to Report to the Capital

The problem gives us a country road network that forms a tree. A tree is a connected graph with no cycles, which means there is exactly one path between any two cities. The cities are numbered from 0 to n - 1, and city 0 is always the capital.

leetcodemediumtreedepth-first-searchbreadth-first-searchgraph-theory
LeetCode 2787 - Ways to Express an Integer as Sum of Powers

This problem asks us to count how many different ways we can represent a given integer n as the sum of distinct positive integers raised to the power x.

leetcodemediumdynamic-programming
CF 152C - Pocket Book

We have a list of n strings, and every string has the same length m. An operation chooses two strings and a prefix length k, then swaps the first k characters between those two strings. We only care about the string that eventually appears in position 1.

codeforcescompetitive-programmingcombinatorics
CF 230B - T-primes

We are asked to identify T-primes in a list of positive integers. A T-prime is defined as a number that has exactly three distinct positive divisors. Thinking about divisors, the only way a number can have exactly three is if it is the square of a prime number.

codeforcescompetitive-programmingbinary-searchimplementationmathnumber-theory
LeetCode 1952 - Three Divisors

The problem asks us to determine whether a given integer n has exactly three positive divisors. In other words, we want to check if there are precisely three distinct integers d such that n % d == 0 and d 0.

leetcodeeasymathenumerationnumber-theory
LeetCode 3075 - Maximize Happiness of Selected Children

The problem gives us an array happiness representing the happiness values of n children standing in a queue and asks us to select exactly k children to maximize the sum of their happiness.

leetcodemediumarraygreedysorting
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 2903 - Find Indices With Index and Value Difference I

The problem asks us to find two indices i and j in the array such that two conditions are satisfied simultaneously: 1. The indices must be far enough apart: 1. The values at those indices must differ enough: We may return any valid pair if multiple answers exist.

leetcodeeasyarraytwo-pointers
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
CF 212A - Privatization

We are given a bipartite graph. One side contains Berland cities, the other side contains Beerland cities, and every flight is an undirected edge between the two countries. Each edge must be assigned to one of t private companies.

codeforcescompetitive-programmingflowsgraphs
LeetCode 2826 - Sorting Three Groups

We are given an array nums where every element is either 1, 2, or 3. In one operation, we may remove any element from the array. Our goal is to make the remaining array non-decreasing while performing the minimum possible number of removals.

leetcodemediumarraybinary-searchdynamic-programming
LeetCode 2650 - Design Cancellable Function

The problem asks us to implement a mechanism to run a generator that yields promises, with the additional ability to cancel the execution at any time.

leetcodehard
LeetCode 2416 - Sum of Prefix Scores of Strings

The problem is asking us to compute a special score for each string in a list of strings. Specifically, for a string term, its score is defined as the number of strings in the array that have term as a prefix.

leetcodehardarraystringtriecounting
LeetCode 2413 - Smallest Even Multiple

The problem asks us to find the smallest positive integer that is a multiple of both 2 and a given positive integer n. In other words, we are looking for the least common multiple (LCM) of 2 and n. The input n is guaranteed to be between 1 and 150, which is a very small range.

leetcodeeasymathnumber-theory
LeetCode 2340 - Minimum Adjacent Swaps to Make a Valid Array

The previous solution fails immediately under a counterexample check. The proposed path was the union of the segments from to the midpoints of and . If the side length is , then the detector radius is The distance from to that path is , while Hence is not detected at all.

leetcodemediumarraygreedy
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 3301 - Maximize the Total Height of Unique Towers

We are given an array maximumHeight where maximumHeight[i] represents the largest height that tower i is allowed to have. Our goal is to assign an actual height to every tower such that: - Every assigned height is a positive integer.

leetcodemediumarraygreedysorting
LeetCode 2206 - Divide Array Into Equal Pairs

The problem gives us an integer array nums containing exactly 2 n elements. Our task is to determine whether it is possible to split the array into n valid pairs, where each pair contains two identical numbers.

leetcodeeasyarrayhash-tablebit-manipulationcounting