brain

tamnd's digital brain — notes, problems, research

42616 notes

LeetCode 2568 - Minimum Impossible OR

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

leetcodemediumarraybit-manipulationbrainteaser
LeetCode 3311 - Construct 2D Grid Matching Graph Layout

The problem gives us an undirected graph with n nodes labeled from 0 to n - 1. We must place every node into a 2D grid so that adjacency in the grid matches adjacency in the graph exactly.

leetcodehardarrayhash-tablegraph-theorymatrix
LeetCode 2374 - Node With Highest Edge Score

The problem asks us to analyze a directed graph where each node has exactly one outgoing edge, represented by the array edges. Each index i represents a node, and edges[i] represents a directed edge from node i to node edges[i].

leetcodemediumhash-tablegraph-theory
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 1990 - Count the Number of Experiments

This problem gives us a database table named Experiments. Each row represents a single experiment performed by a participant. Every experiment belongs to one platform and one experiment category.

leetcodemediumdatabase
LeetCode 2685 - Count the Number of Complete Components

This problem asks us to count how many connected components in an undirected graph are complete graphs. We are given an integer n, representing the number of vertices labeled from 0 to n - 1, and a list of undirected edges.

leetcodemediumdepth-first-searchbreadth-first-searchunion-findgraph-theory
LeetCode 2924 - Find Champion II

This problem models a tournament as a directed acyclic graph (DAG). Each node represents a team, and each directed edge u - v means team u is stronger than team v. A team is considered the champion if no other team is stronger than it.

leetcodemediumgraph-theory
LeetCode 3261 - Count Substrings That Satisfy K-Constraint II

We are given a binary string s, an integer k, and many range queries. For each query [l, r], we only consider the substring s[l..r]. Among all substrings completely contained inside this range, we must count how many satisfy the k-constraint.

leetcodehardarraystringbinary-searchsliding-windowprefix-sum
LeetCode 2916 - Subarrays Distinct Element Sum of Squares II

The problem asks us to consider every possible non-empty subarray of the input array nums. For each subarray, we compute how many distinct values appear inside it. We then square that distinct count, and finally sum the squared values across all subarrays.

leetcodehardarraydynamic-programmingbinary-indexed-treesegment-tree
CF 251B - Playing with Permutations

Codeforces 251B: Playing with Permutations

codeforcescompetitive-programmingimplementationmath
LeetCode 2873 - Maximum Value of an Ordered Triplet I

You are given an integer array nums and must choose three indices (i, j, k) such that: - i < j < k - The triplet value is (nums[i] - nums[j]) nums[k] Among all valid ordered triplets, we want the maximum possible value.

leetcodeeasyarray
LeetCode 1856 - Maximum Subarray Min-Product

The problem asks us to find the maximum min-product of any contiguous subarray of a given integer array nums. The min-product of a subarray is defined as the minimum value in that subarray multiplied by the sum of all elements in that subarray.

leetcodemediumarraystackmonotonic-stackprefix-sum
CF 142B - Help General

We have an n × m chessboard-like grid, and we want to place as many soldiers as possible. Two soldiers conflict if the squared Euclidean distance between their cells is exactly 5. The only integer pairs whose squared distance equals 5 are (1, 2) and (2, 1) up to sign.

codeforcescompetitive-programmingconstructive-algorithmsgreedyimplementation
LeetCode 2452 - Words Within Two Edits of Dictionary

The problem asks us to identify words in the queries list that can be transformed into a word in the dictionary list with at most two character edits. Each edit consists of changing a single character to another lowercase English letter.

leetcodemediumarraystringtrie
LeetCode 1917 - Leetcodify Friends Recommendations

This problem requires generating friend recommendations for users on the Leetcodify platform based on their listening habits. We are given two tables: Listens and Friendship.

leetcodeharddatabase
LeetCode 1910 - Remove All Occurrences of a Substring

The problem asks us to repeatedly remove occurrences of a substring part from a string s. The important detail is that on every operation, we must remove the leftmost occurrence of part. We continue performing removals until part no longer appears anywhere inside s.

leetcodemediumstringstacksimulation
LeetCode 2942 - Find Words Containing Character

The problem asks us to process an array of lowercase strings words and a single lowercase character x, and return all indices of the words that contain this character. In simpler terms, for each string in the array, we must check whether x appears anywhere in that string.

leetcodeeasyarraystring
LeetCode 1993 - Operations on Tree

The problem asks us to design a mutable tree-based data structure that supports three operations: lock, unlock, and upgrade. Each node in the tree may either be unlocked or locked by exactly one user. The operations must follow strict rules about when a node may change state.

leetcodemediumarrayhash-tabletreedepth-first-searchbreadth-first-searchdesign
LeetCode 3235 - Check if the Rectangle Corner Is Reachable

The problem asks whether there is a clear, unobstructed path from the bottom-left corner (0, 0) to the top-right corner (xCorner, yCorner) of a rectangle, such that the path does not touch or go inside any given circles.

leetcodehardarraymathdepth-first-searchbreadth-first-searchunion-findgeometry
CF 424E - Colored Jenga

We are given a vertical stack of levels, each level containing three colored blocks arranged left, middle, right.

codeforcescompetitive-programmingdfs-and-similardpprobabilities
LeetCode 2481 - Minimum Cuts to Divide a Circle

The problem asks for the minimum number of straight cuts required to divide a circle into n equal slices. A valid cut can either pass through the center and touch two points on the circle, or touch one point on the circle and pass through the center.

leetcodeeasymathgeometry
LeetCode 2376 - Count Special Integers

The problem asks us to count how many integers in the range [1, n] contain only distinct digits. A number is considered special if no digit appears more than once in its decimal representation.

leetcodehardmathdynamic-programming
LeetCode 2671 - Frequency Tracker

The problem asks us to design a data structure, FrequencyTracker, that can efficiently track the frequency of numbers and answer queries about whether any number exists with a specific frequency.

leetcodemediumhash-tabledesign
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 2085 - Count Common Words With One Occurrence

This problem gives us two arrays of strings, words1 and words2. Our task is to count how many strings appear exactly once in both arrays. The key detail is that a word only qualifies if: 1. It appears exactly one time in words1 2.

leetcodeeasyarrayhash-tablestringcounting
LeetCode 2585 - Number of Ways to Earn Points

This problem is essentially asking how many distinct ways we can select questions from multiple types to reach exactly a target score. Each type of question has a fixed number of questions (counti) and a fixed number of points per question (marksi).

leetcodehardarraydynamic-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 2943 - Maximize Area of Square Hole in Grid

The grid is formed by n + 2 horizontal bars and m + 2 vertical bars. These bars divide the plane into unit squares. The bars are numbered starting from 1. Some horizontal bars listed in hBars may be removed, and some vertical bars listed in vBars may also be removed.

leetcodemediumarraysorting
LeetCode 2395 - Find Subarrays With Equal Sum

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

leetcodeeasyarrayhash-table
CF 204E - Little Elephant and Strings

We are given a list of strings, and for each string, we need to count the number of its substrings that appear in at least k strings from the list. A substring is any contiguous segment of a string.

codeforcescompetitive-programmingdata-structuresimplementationstring-suffix-structurestwo-pointers
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 2736 - Maximum Sum Queries

We are given two arrays, nums1 and nums2, both of length n. Each index j represents a point: and has an associated value: For every query [xi, yi], we must find an index j such that: and Among all indices satisfying both constraints, we want the maximum possible value: If no…

leetcodehardarraybinary-searchstackbinary-indexed-treesegment-treesortingmonotonic-stack
LeetCode 2199 - Finding the Topic of Each Post

The problem gives us two database tables, Keywords and Posts. The Keywords table maps words to topic IDs. A single topic can have multiple words associated with it, and a single word may belong to multiple topics.

leetcodeharddatabase
LeetCode 2541 - Minimum Operations to Make Array Equal II

LeetCode 2541: Minimum Operations to Make Array Equal II (Medium)

leetcodemediumarraymathgreedy
CF 254C - Anagram

We have two uppercase strings of equal length. We may replace characters in the first string, and after all replacements the final string only needs to be an anagram of the second string.

codeforcescompetitive-programminggreedystrings
LeetCode 2341 - Maximum Number of Pairs in Array

The problem asks us to take an array of integers, nums, and repeatedly form pairs of equal numbers until no more pairs can be formed. Each operation removes exactly two identical numbers from the array, and we continue doing this until it is no longer possible.

leetcodeeasyarrayhash-tablecounting
LeetCode 3240 - Minimum Number of Flips to Make Binary Grid Palindromic II

We are given a binary matrix grid with m rows and n columns. Every cell contains either 0 or 1. We may flip any cell, meaning we can change 0 to 1 or 1 to 0. The goal is to perform the minimum number of flips such that two conditions become true simultaneously: 1.

leetcodemediumarraytwo-pointersmatrix
LeetCode 2877 - Create a DataFrame from List

This problem asks us to create a Pandas DataFrame from a given two dimensional list named studentdata. Each element of studentdata is itself a list containing exactly two values: 1. A student ID 2. The student's age For example: represents four students.

leetcodeeasy
LeetCode 3101 - Count Alternating Subarrays

The problem gives us a binary array nums, meaning every element is either 0 or 1. We need to count how many subarrays are alternating. A subarray is considered alternating if no two adjacent elements inside that subarray are equal.

leetcodemediumarraymath
CF 431D - Random Task

We need to find a positive integer n such that inside the interval (n, 2n], exactly m numbers have exactly k ones in their binary representation.

codeforcescompetitive-programmingbinary-searchbitmaskscombinatoricsdpmath
LeetCode 2977 - Minimum Cost to Convert String II

That is a very large, comprehensive request for a Hard problem, with full sections, worked examples, Python and Go implementations, detailed prose, test cases, and edge case analysis.

leetcodehardarraystringdynamic-programminggraph-theorytrieshortest-path
LeetCode 2789 - Largest Element in an Array after Merge Operations

The problem gives us an array of positive integers and allows a special merge operation between adjacent elements.

leetcodemediumarraygreedy
LeetCode 2464 - Minimum Subarrays in a Valid Split

The problem asks us to split an array of integers nums into contiguous subarrays such that each subarray satisfies a validity condition: the greatest common divisor (GCD) of the first and last elements of the subarray must be strictly greater than 1.

leetcodemediumarraymathdynamic-programmingnumber-theory
CF 253B - Physics Practical

We are given a list of measurement results from a physics experiment. Vasya wants to keep as many measurements as possible, but the remaining set must satisfy one condition: the largest remaining value cannot be more than twice the smallest remaining value.

codeforcescompetitive-programmingbinary-searchdpsortingstwo-pointers
CF 204C - Little Elephant and Furik and Rubik

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

codeforcescompetitive-programmingmathprobabilities
LeetCode 1942 - The Number of the Smallest Unoccupied Chair

This problem describes a scenario where a group of friends attends a party with an infinite number of chairs labeled from 0 upwards. Each friend has a specific arrival and leaving time. When a friend arrives, they must occupy the smallest-numbered unoccupied chair.

leetcodemediumarrayhash-tableheap-(priority-queue)
LeetCode 3352 - Count K-Reducible Numbers Less Than N

The problem asks us to count the number of positive integers less than n (where n is given in binary as a string s) that are k-reducible.

leetcodehardmathstringdynamic-programmingcombinatorics
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 141C - Queue

Each person remembers a single number, how many taller people stood before them in the queue. We no longer know either the original order or the actual heights. The task is to reconstruct any valid queue order together with heights that satisfy every person's remembered value.

codeforcescompetitive-programmingconstructive-algorithmsgreedysortings
LeetCode 2531 - Make Number of Distinct Characters Equal

The problem is a pure inequality with a geometric constraint. The condition that gives by the Pythagorean theorem in . The second condition, that the foot of the perpendicular from to plane is the orthocenter of , is much more restrictive than it first appears.

leetcodemediumhash-tablestringcounting
LeetCode 2030 - Smallest K-Length Subsequence With Occurrences of a Letter

The problem asks us to construct the lexicographically smallest subsequence of length k from the string s, while ensuring that a specific character, letter, appears at least repetition times in the resulting subsequence.

leetcodehardstringstackgreedymonotonic-stack
LeetCode 2225 - Find Players With Zero or One Losses

The problem gives us a list of match results. Each match is represented as a pair: This means the player winner defeated the player loser. Our goal is to return two separate lists: 1. All players who never lost any match. 2. All players who lost exactly one match.

leetcodemediumarrayhash-tablesortingcounting
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 2543 - Check if Point Is Reachable

The problem gives us an infinite two dimensional grid and asks whether we can travel from the starting point (1, 1) to a target point (targetX, targetY) using a specific set of operations.

leetcodehardmathnumber-theory
LeetCode 2107 - Number of Unique Flavors After Sharing K Candies

The problem gives us an integer array candies, where each value represents the flavor of a candy. We must give exactly k consecutive candies to our sister. After removing those k candies, we keep the remaining candies for ourselves.

leetcodemediumarrayhash-tablesliding-window
LeetCode 2223 - Sum of Scores of Built Strings

The problem gives us a final string s and describes a process where the string is built by repeatedly prepending characters to the front. This means that every intermediate string si is actually a suffix of the final string s.

leetcodehardstringbinary-searchrolling-hashsuffix-arraystring-matchinghash-function
LeetCode 2560 - House Robber IV

The problem describes a scenario where a robber wants to steal from houses lined along a street, but with the constraint that adjacent houses cannot both be robbed.

leetcodemediumarraybinary-searchdynamic-programminggreedy
LeetCode 2494 - Merge Overlapping Events in the Same Hall

The problem requires us to merge overlapping events in the same hall. Each row of the HallEvents table represents an event in a particular hall with a startday and an endday. Events are considered overlapping if they share at least one day in common.

leetcodeharddatabase
LeetCode 2743 - Count Substrings Without Repeating Character

The problem asks us to count how many substrings of a given string contain only unique characters. A substring is considered special if no character appears more than once inside that substring. We are given a string s containing only lowercase English letters.

leetcodemediumhash-tablestringsliding-window
LeetCode 3096 - Minimum Levels to Gain More Points

This problem is asking us to determine the minimum number of levels Alice should play in order to score more points than Bob, given that both play optimally and that some levels may be impossible to clear. The input is a binary array possible of length n.

leetcodemediumarrayprefix-sum
LeetCode 3400 - Maximum Number of Matching Indices After Right Shifts

The problem gives us two arrays, nums1 and nums2, both of the same length n. We are allowed to repeatedly perform a right circular shift on nums1. A right shift moves every element one position to the right, and the last element wraps around to the beginning.

leetcodemediumarraytwo-pointerssimulation
LeetCode 2660 - Determine the Winner of a Bowling Game

The problem describes a simplified scoring system for a bowling game between two players. Each player has an array representing the number of pins hit in each turn, and there are exactly n turns.

leetcodeeasyarraysimulation
CF 205B - Little Elephant and Sorting

We are given an array of integers, and one operation consists of choosing a contiguous segment and increasing every element inside that segment by exactly one. We may repeat this operation any number of times.

codeforcescompetitive-programmingbrute-forcegreedy
LeetCode 2382 - Maximum Segment Sum After Removals

The problem gives us two arrays, nums and removeQueries, both of length n. The nums array contains positive integers. Initially, all elements are present, forming one contiguous segment. Then, elements are removed one by one according to the order defined in removeQueries.

leetcodehardarrayunion-findprefix-sumordered-set
LeetCode 2129 - Capitalize the Title

The problem asks us to transform the capitalization of every word in a given title string according to a specific rule based on word length. We are given a string called title, which contains one or more words separated by single spaces.

leetcodeeasystring
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
CF 145A - Lucky Conversion

We are given two strings of equal length, both consisting only of the characters 4 and 7. The goal is to transform the first string into the second using the fewest operations. There are two allowed operations. We may flip a single digit, changing 4 to 7 or 7 to 4.

codeforcescompetitive-programminggreedyimplementation
LeetCode 2431 - Maximize Total Tastiness of Purchased Fruits

This problem asks us to maximize the total tastiness of fruits we purchase while staying within a fixed budget. Each fruit has two attributes: a price and a tastiness value. We may either skip a fruit or buy it, but each fruit can only be purchased once.

leetcodemediumarraydynamic-programming
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 3014 - Minimum Number of Pushes to Type Word I

We are given a word consisting of distinct lowercase English letters. We are allowed to completely redesign the mapping of letters onto the telephone keypad keys 2 through 9. There are 8 available keys (2 to 9).

leetcodeeasymathstringgreedy
LeetCode 3312 - Sorted GCD Pair Queries

=== 1996-G1 === Origin: GBR Let triangle have orthocenter , and let be a point on its circumcircle, distinct from , , . Let be the foot of the altitude , let and be parallelograms, and let meet in . Prove that is parallel to .

leetcodehardarrayhash-tablemathbinary-searchcombinatoricscountingnumber-theoryprefix-sum
CF 263D - Cycle in Graph

We are given an undirected graph where every vertex has a very strong local condition: each node is connected to at least $k$ other distinct nodes. From this structure we are asked to extract a simple cycle whose length is not just positive, but at least $k+1$.

codeforcescompetitive-programmingdfs-and-similargraphs
LeetCode 3006 - Find Beautiful Indices in the Given Array I

The problem gives us a string s and two smaller strings, a and b. We need to find every index i where substring a appears in s, but only if there exists at least one occurrence of substring b close enough to it. More formally, an index i is considered beautiful when: 1.

leetcodemediumtwo-pointersstringbinary-searchrolling-hashstring-matchinghash-function
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 2164 - Sort Even and Odd Indices Independently

The problem asks us to take an integer array nums and sort its elements based on their indices in two separate ways: the elements at even indices should be sorted in non-decreasing order, and the elements at odd indices should be sorted in non-increasing order.

leetcodeeasyarraysorting
CF 159B - Matchmaker

We have two collections of objects. Markers are described by (color, diameter) and caps are also described by (color, diameter). A cap can be attached to a marker only if the diameters are equal.

codeforcescompetitive-programming*specialgreedysortings
LeetCode 2287 - Rearrange Characters to Make Target String

The problem gives us two strings, s and target. We are allowed to take characters from s and rearrange them in any order to form copies of target. Each character in s can only be used once.

leetcodeeasyhash-tablestringcounting
LeetCode 2127 - Maximum Employees to Be Invited to a Meeting

This problem describes a group of employees sitting around a circular table. Every employee has exactly one favorite coworker, represented by the array favorite, where favorite[i] is the person employee i wants to sit next to.

leetcodehardarraydynamic-programmingdepth-first-searchgraph-theorytopological-sort
LeetCode 3366 - Minimum Array Sum

We are given an array nums and two different operations that can reduce the values of elements in the array. The first operation divides a number by 2 and rounds the result upward.

leetcodemediumarraydynamic-programming
CF 215C - Crosses

Each cross is defined by two axis-aligned rectangles centered at the same cell (x0, y0). The first rectangle extends a cells vertically and b cells horizontally from the center, so its size is: $(2a+1)(2b+1)$ The second rectangle is defined similarly using c and d.

codeforcescompetitive-programmingbrute-forceimplementation
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 2817 - Minimum Absolute Difference Between Elements With Constraint

We are given an integer array nums and an integer x. We need to find two elements whose indices are separated by at least x, and among all such valid pairs, return the minimum possible absolute difference between their values.

leetcodemediumarraybinary-searchordered-set
LeetCode 2642 - Design Graph With Shortest Path Calculator

The problem asks us to design a graph data structure that supports two operations efficiently: 1. Dynamically adding directed weighted edges. 2. Finding the shortest path cost between two nodes. We are given a directed weighted graph with n nodes labeled from 0 to n - 1.

leetcodehardgraph-theorydesignheap-(priority-queue)shortest-path
LeetCode 2411 - Smallest Subarrays With Maximum Bitwise OR

The problem asks us to find, for each index in a given array nums, the length of the shortest contiguous subarray starting at that index whose bitwise OR is equal to the maximum possible bitwise OR obtainable from that index onward.

leetcodemediumarraybinary-searchbit-manipulationsliding-window
LeetCode 1828 - Queries on Number of Points Inside a Circle

This problem gives us two collections of geometric objects on a 2D plane. The first collection is an array called points, where each element is a coordinate pair [x, y]. Each pair represents a point on the plane.

leetcodemediumarraymathgeometry
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 2853 - Highest Salaries Difference

The problem provides a database table named Salaries with three columns: | Column | Meaning | | --- | --- | | empname | Employee name | | department | Employee department | | salary | Employee salary | The combination of (empname, department) is unique, meaning there are no…

leetcodeeasydatabase
LeetCode 2168 - Unique Substrings With Equal Digit Frequency

The problem gives us a string s consisting only of digits from '0' to '9'. We must count how many distinct substrings satisfy a special condition: Every digit that appears in the substring must appear the same number of times. A substring is a contiguous portion of the string.

leetcodemediumhash-tablestringrolling-hashcountinghash-function
LeetCode 2333 - Minimum Sum of Squared Difference

I can do that, but the complete guide with all requested sections and the level of detail you specified will exceed a single message limit. I will split it cleanly into multiple parts while preserving your exact formatting requirements. Planned structure: 1.

leetcodemediumarraybinary-searchgreedysortingheap-(priority-queue)
LeetCode 3276 - Select Cells in Grid With Maximum Score

The problem requires us to select cells from a 2D matrix grid such that no two selected cells are in the same row, and all selected values are unique. Our goal is to maximize the sum of these selected values.

leetcodehardarraydynamic-programmingbit-manipulationmatrixbitmask
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
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 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 2083 - Substrings That Begin and End With the Same Letter

The problem asks us to count all substrings in a given string s that start and end with the same character. A substring is a contiguous sequence of characters, so the order and adjacency of characters matter.

leetcodemediumhash-tablemathstringcountingprefix-sum
LeetCode 3130 - Find All Possible Stable Binary Arrays II

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

leetcodeharddynamic-programmingprefix-sum
LeetCode 2418 - Sort the People

This problem gives us two arrays of equal length: - names[i] represents the name of a person - heights[i] represents the height of that same person The two arrays are aligned by index, meaning the person at index i has both the name names[i] and the height heights[i].

leetcodeeasyarrayhash-tablestringsorting
LeetCode 2904 - Shortest and Lexicographically Smallest Beautiful String

We are given a binary string s, meaning the string contains only the characters '0' and '1', along with a positive integer k. The goal is to find a substring of s that is considered beautiful, where a beautiful substring contains exactly k occurrences of '1'.

leetcodemediumstringsliding-window
CF 301D - Yaroslav and Divisors

We are given a permutation of numbers from 1 to n. For every query interval [l, r], we must count how many ordered pairs of positions (q, w) inside that interval satisfy: $$p[q] mid p[w]$$ Since all values are distinct and form a permutation, every number appears exactly once.

codeforcescompetitive-programmingdata-structures
LeetCode 3334 - Find the Maximum Factor Score of Array

The problem asks us to compute the maximum factor score of an array of integers, where the factor score is defined as the product of the GCD (greatest common divisor) and LCM (least common multiple) of all elements in the array.

leetcodemediumarraymathnumber-theory
LeetCode 2366 - Minimum Replacements to Sort the Array

The problem asks us to transform a given integer array nums into a non-decreasing array by performing a sequence of operations. In each operation, we are allowed to replace any single element with any two elements that sum to it.

leetcodehardarraymathgreedy