brain

tamnd's digital brain — notes, problems, research

43815 notes

LeetCode 2439 - Minimize Maximum of Array

The problem gives a 0-indexed array nums of non-negative integers and allows a specific operation: choose an index i (where 1 <= i < n) such that nums[i] 0, then decrease nums[i] by 1 and increase nums[i - 1] by 1.

leetcodemediumarraybinary-searchdynamic-programminggreedyprefix-sum
LeetCode 3307 - Find the K-th Character in String Game II

The problem describes a string manipulation game between Alice and Bob. Initially, Alice starts with a string word = "a". Bob provides a list of operations, represented by the integer array operations.

leetcodehardmathbit-manipulationrecursion
LeetCode 2599 - Make the Prefix Sum Non-negative

The problem asks us to manipulate an array of integers, nums, so that its prefix sums are never negative. A prefix sum at index i is simply the sum of all elements from the start of the array up to i.

leetcodemediumarraygreedyheap-(priority-queue)
CF 182A - Battlefield

We are asked to simulate movement across a 2D plane from a starting point $A$ to a destination $B$ while avoiding a periodic laser. The laser alternates between charging and firing, with durations $a$ and $b$ seconds, respectively.

codeforcescompetitive-programminggeometrygraphsimplementationshortest-paths
LeetCode 2564 - Substring XOR Queries

The problem gives us a binary string s and a list of queries. Each query contains two integers, first and second. For every query, we need to find a substring of s whose decimal value satisfies: where ⊕ represents the bitwise XOR operation.

leetcodemediumarrayhash-tablestringbit-manipulation
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
LeetCode 2060 - Check if an Original String Exists Given Two Encoded Strings

The problem is asking us to determine whether there exists a single original string that could have been encoded into two different given strings, s1 and s2. Each encoded string may contain letters and digits.

leetcodehardstringdynamic-programming
LeetCode 2139 - Minimum Moves to Reach Target Score

The problem asks us to transform the integer 1 into the integer target using the minimum number of moves. At every move, we are allowed to perform one of two operations: 1. Increment the current number by 1 2.

leetcodemediummathgreedy
LeetCode 2778 - Sum of Squares of Special Elements

This problem asks us to compute the sum of squares of certain elements in an array, specifically the special elements. The array nums is 1-indexed, meaning the first element is at index 1 (not 0).

leetcodeeasyarrayenumeration
CF 252B - Unsorting Array

We are given an array of integers of length n and asked to determine if we can swap any two elements at distinct positions such that the resulting array is no longer sorted. Sorting here is defined broadly: the array is sorted if it is either non-decreasing or non-increasing.

codeforcescompetitive-programmingbrute-forcesortings
LeetCode 2851 - String Transformation

The problem asks us to transform a string s into a target string t using a very specific operation: choosing a non-empty suffix of s (not the whole string) and moving it to the front.

leetcodehardmathstringdynamic-programmingstring-matching
LeetCode 3139 - Minimum Cost to Equalize Array

This problem asks us to determine the minimum cost to make all elements in an array equal. You are allowed two types of operations: increment a single element at a cost of cost1, or increment any two distinct elements simultaneously at a cost of cost2.

leetcodehardarraygreedyenumeration
LeetCode 3306 - Count of Substrings Containing Every Vowel and K Consonants II

The problem asks us to count how many substrings of a given string satisfy two conditions simultaneously: 1. The substring contains all five vowels, 'a', 'e', 'i', 'o', and 'u', at least once. 2. The substring contains exactly k consonants.

leetcodemediumhash-tablestringsliding-window
CF 169B - Replacing Digits

We are given a decimal number as a string and another string containing extra digits that we may use for replacements. Every digit from the second string can be used at most once. For each chosen digit, we may replace any single position in the original number.

codeforcescompetitive-programminggreedy
LeetCode 2140 - Solving Questions With Brainpower

The problem gives us an array called questions, where each element contains two integers: - questions[i][0] represents the number of points earned if we solve question i - questions[i][1] represents how many subsequent questions must be skipped after solving question i We must…

leetcodemediumarraydynamic-programming
LeetCode 1972 - First and Last Call On the Same Day

The problem provides a table of phone call records where each row contains a caller, a recipient, and a timestamp. Each call is bidirectional in the sense that both participants are considered to have made and received the call simultaneously.

leetcodeharddatabase
LeetCode 2979 - Most Expensive Item That Can Not Be Bought

This problem asks us to determine the largest price that cannot be formed using an unlimited number of coins of two given prime denominations. We are given two distinct prime numbers, primeOne and primeTwo.

leetcodemediummathdynamic-programmingnumber-theory
CF 162C - Prime factorization

We are asked to take a positive integer and express it as a product of prime numbers, showing each prime the number of times it appears in the factorization. For example, the number 245 can be expressed as 5 multiplied by 7 twice, so the output would be 577.

codeforcescompetitive-programming*special
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 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
CF 219A - k-String

We are given a lowercase string and an integer k. We may rearrange the letters however we want. The goal is to build a new string that consists of exactly k identical blocks placed one after another.

codeforcescompetitive-programmingimplementationstrings
LeetCode 2728 - Count Houses in a Circular Street

The problem asks us to determine the number of houses on a circular street where we can only interact with the street through the provided Street interface. Each house has a door that can either be open or closed.

leetcodeeasyarrayinteractive
LeetCode 1876 - Substrings of Size Three with Distinct Characters

The problem asks us to count how many substrings of length exactly three contain only distinct characters. A substring is a continuous portion of the string, so for every position in the string, we can examine the next three consecutive characters and determine whether all…

leetcodeeasyhash-tablestringsliding-windowcounting
LeetCode 2985 - Calculate Compressed Mean

This problem asks us to compute the average number of items per order from a compressed representation of order data. Instead of storing every individual order as a separate row, the table groups together orders that contain the same number of items.

leetcodeeasydatabase
LeetCode 1915 - Number of Wonderful Substrings

The problem asks us to count how many non-empty substrings of a given string are considered "wonderful". A substring is wonderful if at most one character appears an odd number of times inside that substring.

leetcodemediumhash-tablestringbit-manipulationprefix-sum
LeetCode 3379 - Transformed Array

The problem asks us to transform a given integer array nums into a new array result following specific movement rules. Each element in nums determines how many steps to move in a circular manner, either to the right (if positive) or left (if negative).

leetcodeeasyarraysimulation
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
LeetCode 2794 - Create Object from Two Arrays

The problem provides two arrays, keysArr and valuesArr, which always have the same length. Each position in the arrays represents a potential key-value pair.

leetcodeeasy
LeetCode 2043 - Simple Bank System

This problem asks us to design a very simple banking system that supports three operations: 1. Transfer money between two accounts 2. Deposit money into an account 3. Withdraw money from an account The bank contains n accounts numbered from 1 to n.

leetcodemediumarrayhash-tabledesignsimulation
LeetCode 2267 - Check if There Is a Valid Parentheses String Path

This problem is asking us to determine whether there exists a path from the top-left corner (0, 0) to the bottom-right corner (m-1, n-1) of a 2D grid containing only '(' and ')' characters, such that the sequence of characters along the path forms a valid parentheses string.

leetcodehardarraydynamic-programmingmatrix
LeetCode 2662 - Minimum Cost of a Path With Special Roads

The problem asks us to find the minimum cost to move from a starting point start = [startX, startY] to a target point target = [targetX, targetY] in a 2D plane.

leetcodemediumarraygraph-theoryheap-(priority-queue)shortest-path
LeetCode 3339 - Find the Number of K-Even Arrays

We are given three integers: - n, the length of the array. - m, the maximum value allowed in the array. - k, the exact number of special adjacent positions we want. Every element of the array must be chosen from the range [1, m].

leetcodemediumdynamic-programming
LeetCode 2044 - Count Number of Maximum Bitwise-OR Subsets

The problem asks us to examine every possible non-empty subset of the given array nums and compute the bitwise OR value of each subset. Among all these OR values, we need to determine the maximum possible value, then count how many different subsets produce that maximum.

leetcodemediumarraybacktrackingbit-manipulationenumeration
LeetCode 2447 - Number of Subarrays With GCD Equal to K

The problem gives us an integer array nums and an integer k. We need to count how many contiguous subarrays have a greatest common divisor (GCD) exactly equal to k. A subarray is any non-empty contiguous segment of the array.

leetcodemediumarraymathnumber-theory
LeetCode 1808 - Maximize Number of Nice Divisors

The problem gives us an integer primeFactors, representing the maximum total number of prime factors we are allowed to use when constructing some positive integer n. The goal is not to maximize n itself. Instead, we want to maximize the number of "nice divisors" of n.

leetcodehardmathrecursionnumber-theory
LeetCode 3099 - Harshad Number

The problem asks us to determine whether a given integer is a Harshad number. A Harshad number is an integer that is divisible by the sum of its digits. We are given a single integer x, and we must perform two operations: 1. Compute the sum of all digits in x 2.

leetcodeeasymath
LeetCode 3046 - Split the Array

The problem asks us to determine if an even-length array can be split into two equal-sized subarrays, each containing only distinct elements.

leetcodeeasyarrayhash-tablecounting
LeetCode 3314 - Construct the Minimum Bitwise Array I

The problem asks us to construct an array ans from a given array nums of prime integers. For each element nums[i], we need to find the smallest integer ans[i] such that the bitwise OR of ans[i] and ans[i] + 1 equals nums[i]. Formally, ans[i] | (ans[i] + 1) == nums[i].

leetcodeeasyarraybit-manipulation
LeetCode 2314 - The First Day of the Maximum Recorded Degree in Each City

The problem gives us a database table named Weather that stores temperature readings for different cities on specific days in the year 2022.

leetcodemediumdatabase
LeetCode 2208 - Minimum Operations to Halve Array Sum

This problem asks us to repeatedly reduce numbers in an array until the total sum of the array has been reduced by at least half, while using the minimum number of operations.

leetcodemediumarraygreedyheap-(priority-queue)
LeetCode 3298 - Count Substrings That Can Be Rearranged to Contain a String II

We are given two strings, word1 and word2. We need to count how many substrings of word1 are considered valid. A substring is valid if its characters can be rearranged so that word2 becomes a prefix of the rearranged string.

leetcodehardhash-tablestringsliding-window
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
CF 209B - Pixels

We start with three piles of pixels, one red, one green, and one blue. A fight can only happen between two different colors. When that happens, one pixel survives and immediately changes into the third color.

codeforcescompetitive-programmingconstructive-algorithmsmath
LeetCode 3082 - Find the Sum of the Power of All Subsequences

You are given an array nums and an integer k. For every subsequence of nums, we define its power as the number of subsequences inside it whose sum equals k. The task is to compute the total power across all subsequences of the original array.

leetcodehardarraydynamic-programming
LeetCode 1892 - Page Recommendations II

The problem asks us to implement a page recommendation system based on users’ friendships and their page likes. We are given two database tables: Friendship and Likes.

leetcodeharddatabase
LeetCode 2150 - Find All Lonely Numbers in the Array

The corridor is represented as a string where each character is either 'S' for a seat or 'P' for a plant. We already have fixed dividers at both ends of the corridor, and we may optionally place additional dividers between adjacent positions.

leetcodemediumarrayhash-tablecounting
LeetCode 2490 - Circular Sentence

The problem asks us to determine whether a given sentence is circular. A sentence is defined as a string of words separated by a single space, with no leading or trailing spaces. Words contain only uppercase and lowercase English letters.

leetcodeeasystring
LeetCode 3154 - Find Number of Ways to Reach the K-th Stair

Let's dive into a comprehensive solution guide for LeetCode 3154 - Find Number of Ways to Reach the K-th Stair. This problem involves Alice navigating a staircase starting at stair 1, aiming to reach stair k.

leetcodehardmathdynamic-programmingbit-manipulationmemoizationcombinatorics
CF 401D - Roman and Numbers

We are asked to count the number of integers that can be formed by permuting the digits of a given number $n$, do not start with zero, and are divisible by a given modulus $m$. The input $n$ can be as large as $10^{18}$, which means up to 18 digits, and $m$ is at most 100.

codeforcescompetitive-programmingbitmasksbrute-forcecombinatoricsdpnumber-theory
LeetCode 2278 - Percentage of Letter in String

This problem asks us to calculate the percentage of a given character, letter, in a string s, and return it as an integer rounded down to the nearest whole percent.

leetcodeeasystring
CF 160A - Twins

We are given a collection of coins, each with a positive integer value. The task is to choose a subset of these coins such that the total value of our chosen coins is strictly greater than the total value of the coins left for the other person.

codeforcescompetitive-programminggreedysortings
LeetCode 1902 - Depth of BST Given Insertion Order

The problem gives us an array order that represents the exact sequence in which values are inserted into a binary search tree, usually abbreviated as BST. The array is a permutation of integers from 1 to n, which means every value appears exactly once and there are no duplicates.

leetcodemediumarraytreebinary-search-treebinary-treeordered-set
LeetCode 2289 - Steps to Make Array Non-decreasing

The problem asks us to determine how many steps it takes to make a given array nums non-decreasing by repeatedly removing elements that break the non-decreasing property. Specifically, for each step, any element nums[i] where nums[i - 1] nums[i] is removed.

leetcodemediumarraylinked-listdynamic-programmingstackmonotonic-stacksimulation
LeetCode 3048 - Earliest Second to Mark Indices I

We are given two 1-indexed arrays: - nums, where nums[i] represents how many decrement operations index i still needs before it becomes zero. - changeIndices, where changeIndices[s] tells us which index is eligible to be marked at second s. Initially, every index is unmarked.

leetcodemediumarraybinary-search
CF 201A - Clear Symmetry

We are asked to construct a square matrix of size n × n, filled with zeros and ones, that satisfies two properties: it must be clear, meaning that no two ones are adjacent horizontally or vertically, and it must be symmetrical along both the horizontal and vertical axes.

codeforcescompetitive-programmingconstructive-algorithmsdpmath
LeetCode 2248 - Intersection of Multiple Arrays

The problem is asking us to find the intersection of multiple arrays. Specifically, given a 2D array nums, where each nums[i] is a non-empty array of distinct positive integers, we want to identify which integers appear in every array in nums.

leetcodeeasyarrayhash-tablesortingcounting
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 2114 - Maximum Number of Words Found in Sentences

In this problem, we are given an array of strings called sentences. Each string represents a sentence composed of lowercase English words separated by exactly one space. The problem asks us to determine the maximum number of words that appear in any single sentence.

leetcodeeasyarraystring
LeetCode 3202 - Find the Maximum Length of Valid Subsequence II

This problem asks us to find the length of the longest subsequence in an array nums such that for every consecutive pair of elements in the subsequence, the sum of the pair modulo k is the same. In other words, if we denote a valid subsequence as sub = [a1, a2, ...

leetcodemediumarraydynamic-programming
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
LeetCode 2275 - Largest Combination With Bitwise AND Greater Than Zero

The problem asks us to find the largest possible group of numbers from the candidates array such that the bitwise AND of every number in that group is greater than 0. A bitwise AND operation only keeps bits that are set to 1 in every participating number.

leetcodemediumarrayhash-tablebit-manipulationcounting
LeetCode 2589 - Minimum Time to Complete All Tasks

This problem is asking us to determine the minimum amount of time that a computer must be turned on to execute a set of tasks, given that each task has a specified time window [starti, endi] and requires a total duration durationi that does not need to be continuous.

leetcodehardarraybinary-searchstackgreedysorting
LeetCode 2833 - Furthest Point From Origin

This problem asks us to determine the maximum possible distance from the origin after performing a sequence of moves on a number line. We start at position 0, and we are given a string moves, where each character represents one movement instruction.

leetcodeeasystringcounting
CF 414B - Mashmokh and ACM

We are asked to count how many sequences of fixed length we can build from integers between 1 and n, with two constraints. First, the sequence is non-decreasing. Second, every element must divide the next one in the sequence.

codeforcescompetitive-programmingcombinatoricsdpnumber-theory
LeetCode 3305 - Count of Substrings Containing Every Vowel and K Consonants I

The problem asks us to count all substrings of a given string word that satisfy two conditions simultaneously: first, the substring must contain all five vowels 'a', 'e', 'i', 'o', and 'u' at least once; second, the substring must contain exactly k consonants.

leetcodemediumhash-tablestringsliding-window
LeetCode 1861 - Rotating the Box

Please provide the specific problem number/title you want the detailed solution guide for (for example, “LeetCode 1861 - Rotating the Box”), and I will format it exactly according to your requirements.

leetcodemediumarraytwo-pointersmatrix
LeetCode 2530 - Maximal Score After Applying K Operations

The problem asks us to maximize a score after performing exactly k operations on an array of integers. Each operation allows us to choose any element nums[i], add its value to the score, and then replace it with its ceiling division by 3.

leetcodemediumarraygreedyheap-(priority-queue)
LeetCode 2668 - Find Latest Salaries

This problem gives us a database table named Salary that stores employee salary records. Each employee may appear multiple times because older salary records are still kept in the table.

leetcodeeasydatabase
LeetCode 3282 - Reach End of Array With Max Score

We are given an integer array nums, where each position represents a possible jump starting point. We begin at index 0 and must eventually reach index n - 1. From any index i, we may jump to any later index j where j i.

leetcodemediumarraygreedy
LeetCode 3196 - Maximize Total Cost of Alternating Subarrays

The problem gives us an integer array nums, and we must divide the array into one or more contiguous subarrays. Every element must belong to exactly one subarray.

leetcodemediumarraydynamic-programming
LeetCode 2467 - Most Profitable Path in a Tree

The problem presents a rooted tree with n nodes numbered from 0 to n-1, where node 0 is the root. Each node has a gate that can either cost money to open (negative value) or give a reward (positive value). Alice starts at the root, and Bob starts at a specified node.

leetcodemediumarraytreedepth-first-searchbreadth-first-searchgraph-theory
CF 301B - Yaroslav and Time

We are given a set of stations placed on a 2D grid. Moving between any two stations takes time proportional to their Manhattan distance multiplied by a constant factor $d$.

codeforcescompetitive-programmingbinary-searchgraphsshortest-paths
CF 149C - Division into Teams

We have a group of boys, each with a skill level in football. The task is to split them into two teams such that the teams are nearly equal in size and the total skill levels of the teams are roughly balanced.

codeforcescompetitive-programminggreedymathsortings
LeetCode 3077 - Maximum Strength of K Disjoint Subarrays

The problem is asking us to select exactly k disjoint subarrays from a given array nums such that the last element of each subarray comes before the first element of the next subarray.

leetcodehardarraydynamic-programmingprefix-sum
LeetCode 3300 - Minimum Element After Replacement With Digit Sum

The problem asks us to transform an array of integers nums by replacing each element with the sum of its digits. After this transformation, we need to determine the minimum element in the resulting array.

leetcodeeasyarraymath
CF 215D - Hot Days

We are asked to transport a group of schoolchildren through a sequence of regions along a single road. Each region has a fixed outdoor temperature and a maximum tolerable bus temperature. Every child inside a bus above that tolerable temperature triggers a monetary penalty.

codeforcescompetitive-programminggreedy
CF 163A - Substring and Subsequence

We are given two strings, s and t, and we are asked to count how many distinct pairs (x, y) exist such that x is a substring of s, y is a subsequence of t, and x and y are equal as strings. The key distinction is in how “distinct” is defined.

codeforcescompetitive-programmingdp
LeetCode 2776 - Convert Callback Based Function to Promise Based Function

This problem asks us to implement a utility function called promisify. The purpose of this function is to convert a callback-based asynchronous API into a Promise-based API. The input is a function fn.

leetcodemedium
LeetCode 2775 - Undefined to Null

The problem requires us to recursively traverse a nested object or array and replace all occurrences of undefined with null. In JavaScript, undefined and null behave differently when serializing objects to JSON. Specifically, JSON.

leetcodemedium
CF 311B - Cats Transport

We have a farm with a straight road and several hills numbered from 1 to n. Each hill is separated from the previous one by a known distance. There are m cats, each of which finishes wandering on a particular hill at a certain time, and waits there for a feeder.

codeforcescompetitive-programmingdata-structuresdp
LeetCode 2692 - Make Object Immutable

This problem asks us to create an immutable wrapper around a JSON object or array. The returned structure must behave exactly like the original data for read operations, but any attempt to mutate it must immediately throw a string error with a very specific format.

leetcodemedium
LeetCode 1879 - Minimum XOR Sum of Two Arrays

The problem asks us to take two integer arrays of equal length, nums1 and nums2, and rearrange the elements of nums2 to minimize the XOR sum. The XOR sum is computed as (nums1[0] XOR nums2[0]) + (nums1[1] XOR nums2[1]) + ... + (nums1[n - 1] XOR nums2[n - 1]).

leetcodehardarraydynamic-programmingbit-manipulationbitmask
CF 164E - Polycarpus and Tasks

Polycarpus has a sequence of tasks, each with a start window, an end window, and a duration. Formally, task i is represented by (li, ri, ti).

codeforcescompetitive-programming
CF 152D - Frames

We are given an n × m grid where some cells are painted with and the others are empty .. The picture is supposed to come from painting exactly two rectangular frames. A frame is not a filled rectangle. Only the border cells of the rectangle are painted.

codeforcescompetitive-programmingbrute-force
LeetCode 2205 - The Number of Users That Are Eligible for Discount

The problem gives us a table named Purchases, where each row represents a purchase made by a user. Every record contains three fields: - userid, identifying the customer - timestamp, indicating when the purchase happened - amount, representing how much money was spent The pair…

leetcodeeasydatabase
LeetCode 2908 - Minimum Sum of Mountain Triplets I

The problem asks us to find the minimum possible sum of a "mountain triplet" within a given array of integers. A mountain triplet is defined as three indices (i, j, k) such that i < j < k, nums[i] < nums[j], and nums[k] < nums[j].

leetcodeeasyarray
LeetCode 2390 - Removing Stars From a String

This problem asks us to repeatedly process a string that contains lowercase English letters and star characters (). Every star represents a removal operation. When we encounter a star, we must remove two things: 1. The star itself. 2.

leetcodemediumstringstacksimulation
LeetCode 2929 - Distribute Candies Among Children II

The problem asks us to calculate the total number of ways to distribute n candies among exactly three children, with the constraint that no child can receive more than limit candies.

leetcodemediummathcombinatoricsenumeration
LeetCode 2354 - Number of Excellent Pairs

The problem provides a 0-indexed array of positive integers nums and a positive integer k. The task is to count all distinct pairs (num1, num2) such that both numbers exist in nums and the sum of the number of set bits in num1 OR num2 and num1 AND num2 is at least k.

leetcodehardarrayhash-tablebinary-searchbit-manipulation
LeetCode 2718 - Sum of Matrix After Queries

The problem gives us an integer n representing the size of an n x n matrix. Initially, every cell in the matrix contains 0. We are also given a list of queries.

leetcodemediumarrayhash-table
LeetCode 2666 - Allow One Function Call

This problem asks us to create a wrapper around an existing function fn such that the wrapped version can only execute the original function one time. In other words, we are given a function fn, and we must return a new function.

leetcodeeasy
LeetCode 2940 - Find Building Where Alice and Bob Can Meet

You are given an array heights, where each index represents a building and the value represents that building's height.

leetcodehardarraybinary-searchstackbinary-indexed-treesegment-treeheap-(priority-queue)monotonic-stack
LeetCode 1869 - Longer Contiguous Segments of Ones than Zeros

The problem gives us a binary string s, which means the string contains only the characters '0' and '1'. We need to determine whether the longest contiguous sequence of 1s is strictly longer than the longest contiguous sequence of 0s.

leetcodeeasystring
CF 224A - Parallelepiped

We are given three positive integers representing the areas of three faces of a rectangular parallelepiped that meet at a single vertex.

codeforcescompetitive-programmingbrute-forcegeometrymath
CF 239B - Easy Tape Programming

We are given a string consisting of digits, <, and characters. Every query selects a substring and treats it as a standalone program in a tiny tape language. The interpreter keeps two pieces of state.

codeforcescompetitive-programmingbrute-forceimplementation
LeetCode 2478 - Number of Beautiful Partitions

The problem asks us to count the number of ways to split a given string s of digits into exactly k non-overlapping substrings, where each substring satisfies specific rules: it must start with a prime digit (2, 3, 5, 7), end with a non-prime digit (1, 4, 6, 8, 9), and have…

leetcodehardstringdynamic-programmingprefix-sum
LeetCode 3244 - Shortest Distance After Road Addition Queries II

The problem presents a sequence of n cities numbered from 0 to n - 1 with an initial chain of unidirectional roads such that city i is connected to city i + 1 for all valid i. You are given a list of queries where each query adds a new road from city ui to city vi.

leetcodehardarraygreedygraph-theoryordered-set
CF 429C - Guess the Tree

The problem asks us to reconstruct a rooted tree given constraints on the sizes of the subtrees for each node. You are given an array c of length n, where c[i] represents the total number of nodes in the subtree rooted at node i.

codeforcescompetitive-programmingbitmasksconstructive-algorithmsdpgreedytrees
LeetCode 2281 - Sum of Total Strength of Wizards

The problem asks us to compute the sum of total strengths across every possible contiguous subarray of the input array strength.

leetcodehardarraystackmonotonic-stackprefix-sum
LeetCode 2204 - Distance to a Cycle in Undirected Graph

This problem gives us a connected undirected graph with n nodes and exactly n edges. A connected graph with n nodes normally forms a tree when it has n - 1 edges. Since this graph has one extra edge, it contains exactly one cycle.

leetcodeharddepth-first-searchbreadth-first-searchgraph-theorytopological-sort