brain

tamnd's digital brain — notes, problems, research

42616 notes

CF 138C - Mushroom Gnomes - 2

We have trees placed on a number line. Each tree may fall left, fall right, or remain standing. The probabilities for these three outcomes are given independently for every tree. A falling tree destroys mushrooms in a half-open interval determined by the tree position and height.

codeforcescompetitive-programmingbinary-searchdata-structuresprobabilitiessortings
LeetCode 2209 - Minimum White Tiles After Covering With Carpets

The problem presents a binary string floor representing a row of tiles, where '0' corresponds to a black tile and '1' corresponds to a white tile.

leetcodehardstringdynamic-programmingprefix-sum
LeetCode 2836 - Maximize Value of Function in a Ball Passing Game

This problem presents a ball-passing game among n players, represented by an array receiver of length n. Each element receiver[i] indicates which player receives the ball when player i passes it. The game starts by selecting a player i as the first to hold the ball.

leetcodehardarraydynamic-programmingbit-manipulation
LeetCode 2949 - Count Beautiful Substrings II

The problem asks us to find the number of non-empty substrings in a given string s that satisfy two conditions simultaneously. First, the substring must have an equal number of vowels and consonants.

leetcodehardhash-tablemathstringnumber-theoryprefix-sum
LeetCode 2829 - Determine the Minimum Sum of a k-avoiding Array

The problem asks us to construct an array of n distinct positive integers such that no two elements in the array sum to a given integer k. This type of array is called k-avoiding.

leetcodemediummathgreedy
CF 255D - Mr. Bender and Square

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

codeforcescompetitive-programmingbinary-searchimplementationmath
CF 241C - Mirror Box

The system describes a rectangular box where a laser beam enters through one small hole on the left wall and must exit through another hole on the right wall. Inside the box, there are horizontal mirror segments placed either on the floor or on the ceiling.

codeforcescompetitive-programminggeometryimplementation
LeetCode 2094 - Finding 3-Digit Even Numbers

The problem gives us an array named digits, where every element is a single decimal digit from 0 to 9. We must use exactly three elements from this array to build valid three digit integers.

leetcodeeasyarrayhash-tablerecursionsortingenumeration
CF 216B - Forming Teams

We can model the students as an undirected graph. Each student is a vertex, and every pair of enemies creates an edge. We want to split the remaining students into two teams of equal size such that no edge stays inside one team.

codeforcescompetitive-programmingdfs-and-similarimplementation
LeetCode 2256 - Minimum Average Difference

In this problem, we are given a 0-indexed integer array nums, and for every index i, we must compute something called the "average difference".

leetcodemediumarrayprefix-sum
LeetCode 1931 - Painting a Grid With Three Different Colors

The problem is asking us to count the number of ways to paint an m x n grid using three colors: red, green, and blue, with the constraint that no two adjacent cells can have the same color. Adjacent cells include both vertically and horizontally neighboring cells.

leetcodeharddynamic-programming
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
CF 241E - Flights

We are given a directed acyclic graph of cities and one-way flights. Every flight initially takes 1 hour. We may independently change any flight duration to either 1 or 2 hours.

codeforcescompetitive-programminggraphsshortest-paths
LeetCode 1967 - Number of Strings That Appear as Substrings in Word

The problem asks us to determine how many strings in the array patterns appear as substrings within a given string word. A substring is defined as a contiguous sequence of characters, meaning the characters must appear in order and without gaps inside word.

leetcodeeasyarraystring
LeetCode 2807 - Insert Greatest Common Divisors in Linked List

This problem gives us the head of a singly linked list where every node contains a positive integer. Our task is to modify the list by inserting a new node between every pair of adjacent nodes.

leetcodemediumlinked-listmathnumber-theory
LeetCode 2804 - Array Prototype ForEach

This problem asks us to implement a custom version of the forEach method for arrays in JavaScript. The goal is to extend the Array.prototype so that any array can call forEach(callback, context) and execute the callback on each element.

leetcodeeasy
LeetCode 2982 - Find Longest Special Substring That Occurs Thrice II

The problem asks us to find the maximum length of a special substring that appears at least three times in the given string. A substring is considered special if it consists entirely of a single repeated character.

leetcodemediumhash-tablestringbinary-searchsliding-windowcounting
CF 248B - Chilly Willy

We are looking for the smallest positive integer that has exactly n digits and is divisible by every one of the numbers 2, 3, 5, and 7 at the same time. In other words, we want the minimal n-digit number that is a multiple of the least common multiple of those four integers.

codeforcescompetitive-programmingmathnumber-theory
LeetCode 2669 - Count Artist Occurrences On Spotify Ranking List

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

leetcodeeasydatabase
LeetCode 2690 - Infinite Method Object

This problem asks us to implement a function that returns an infinite-method object. The defining property of this object is that any method name can be accessed and called, and when invoked, it should return the exact name of the method.

leetcodeeasy
LeetCode 2872 - Maximum Number of K-Divisible Components

This problem is asking us to split a given undirected tree into as many connected components as possible, under the condition that the sum of values of nodes in each component is divisible by a given integer k.

leetcodehardtreedepth-first-search
CF 159E - Zebra Tower

We have n cubes. Every cube has a color and a size. We want to build a tower using cubes from exactly two distinct colors, and adjacent cubes in the tower must always have different colors. There are no restrictions on cube sizes or ordering.

codeforcescompetitive-programming*specialdata-structuresgreedysortings
CF 173C - Spiral Maximum

We are given a rectangular grid of integers. Inside this grid, we may place any odd-sized square, for example a 3×3, 5×5, or 7×7 subgrid. Inside that square we draw the standard spiral that starts at the top-left corner and winds inward. The spiral does not visit every cell.

codeforcescompetitive-programmingbrute-forcedp
LeetCode 1924 - Erect the Fence II

Here is a fully detailed technical solution guide for LeetCode 1924 - Erect the Fence II, following your formatting instructions: The problem asks us to compute the minimum enclosing circle for a set of points in 2D space, where each point represents a tree.

leetcodehardarraymathgeometry
CF 162J - Brackets

We are given a string consisting solely of opening and closing round brackets. The task is to determine whether this sequence is balanced, meaning it could represent a correct arrangement of parentheses in a mathematical expression.

codeforcescompetitive-programming*special
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
CF 144E - Competition

We are given a triangular region of a square matrix called an n-degree staircase. In this staircase, each cell is accessible except for the area above the secondary diagonal, which runs from the top right to the bottom left.

codeforcescompetitive-programmingdata-structuresgreedy
CF 303E - Random Ranking

Each participant receives a real-valued score chosen uniformly from an interval $[li, ri]$. Scores are independent. After all scores are generated, participants are sorted by score. Smaller score means better rank, so the participant with the largest score finishes last.

codeforcescompetitive-programmingdpmathprobabilities
LeetCode 2973 - Find Number of Coins to Place in Tree Nodes

The problem gives us a tree with n nodes labeled from 0 to n - 1. The tree is undirected and rooted at node 0. The tree structure is described by the edges array, where each edge [a, b] connects nodes a and b. Each node also has an associated cost, given in the cost array.

leetcodeharddynamic-programmingtreedepth-first-searchsortingheap-(priority-queue)
LeetCode 3290 - Maximum Multiplication Score

This problem gives us two integer arrays: - a, which always has exactly 4 elements. - b, which has length at least 4 and can be as large as 100,000. We must select exactly four indices from b: The score obtained from such a selection is: Our goal is to maximize this score.

leetcodemediumarraydynamic-programming
LeetCode 2125 - Number of Laser Beams in a Bank

The problem describes a bank floor plan as a binary matrix, represented by an array of strings. Each row corresponds to one row in the bank, and each character in the string represents a cell.

leetcodemediumarraymathstringmatrix
LeetCode 3245 - Alternating Groups III

We are given a circular array called colors, where each element is either 0 or 1. These represent red and blue tiles arranged in a ring, which means index 0 and index n - 1 are adjacent.

leetcodehardarraybinary-indexed-treeordered-set
LeetCode 3236 - CEO Subordinate Hierarchy

This problem requires building a hierarchical view of a company's employee structure starting from the CEO. The Employees table contains employee records, including their unique ID, name, manager ID, and salary. The CEO is identified as the employee with a NULL managerid.

leetcodeharddatabase
LeetCode 2149 - Rearrange Array Elements by Sign

The problem asks us to rearrange a given integer array nums such that positive and negative numbers alternate, starting with a positive number. The array has an even length and contains an equal number of positive and negative integers.

leetcodemediumarraytwo-pointerssimulation
CF 306A - Candies

Polycarpus has a certain number of candies and a number of friends. He wants to distribute all the candies among his friends in such a way that every friend gets a positive number of candies, and the difference between the friend who receives the most candies and the friend…

codeforcescompetitive-programmingimplementation
LeetCode 2756 - Query Batching

The problem asks us to design a throttled batching system for asynchronous queries. Instead of immediately sending every incoming request individually, we want to intelligently combine multiple requests together whenever possible.

leetcodehard
LeetCode 2892 - Minimizing Array After Replacing Pairs With Their Product

The problem gives us an integer array nums and a value k. We are allowed to repeatedly merge adjacent elements under one condition: - If two adjacent values x and y satisfy x y <= k, then we may replace them with a single value equal to x y.

leetcodemediumarraydynamic-programminggreedy
LeetCode 2860 - Happy Students

The problem asks us to determine the number of ways to select a subset of students from a class such that every student is happy according to the given rules. Each student has a number nums[i] that represents a threshold.

leetcodemediumarraysortingenumeration
LeetCode 2521 - Distinct Prime Factors of Product of Array

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

leetcodemediumarrayhash-tablemathnumber-theory
LeetCode 3168 - Minimum Number of Chairs in a Waiting Room

The problem gives us a string s that represents events happening in a waiting room over time. Each character corresponds to one second. If the character is 'E', one person enters the room and occupies a chair. If the character is 'L', one person leaves the room and frees a chair.

leetcodeeasystringsimulation
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 2065 - Maximum Path Quality of a Graph

We are given an undirected weighted graph where each node has an associated value. A path is considered valid if: 1. It starts at node 0 2. It ends at node 0 3.

leetcodehardarraybacktrackinggraph-theory
LeetCode 2147 - Number of Ways to Divide a Long Corridor

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

leetcodehardmathstringdynamic-programming
LeetCode 3207 - Maximum Points After Enemy Battles

The problem gives us a list of enemies, where each enemy has an associated energy value. We also start with some initial amount of energy called currentEnergy. We begin with zero points, and every enemy starts as unmarked.

leetcodemediumarraygreedy
LeetCode 2720 - Popularity Percentage

The Friends table stores friendship relationships between users on a social platform. Each row contains two user IDs, user1 and user2, indicating that those two users are friends with each other.

leetcodeharddatabase
LeetCode 2135 - Count Words Obtained After Adding a Letter

The problem requires us to determine how many strings in targetWords can be formed from strings in startWords through a specific transformation.

leetcodemediumarrayhash-tablestringbit-manipulationsorting
LeetCode 3193 - Count the Number of Inversions

The problem asks us to count how many permutations of the numbers [0, 1, 2, ..., n - 1] satisfy a collection of inversion constraints on prefixes.

leetcodehardarraydynamic-programming
CF 448D - Multiplication Table

We are working with a conceptual multiplication grid where the cell in row i and column j contains the value i × j. Instead of explicitly building this table, we imagine listing all n × m values and sorting them in non-decreasing order.

codeforcescompetitive-programmingbinary-searchbrute-force
LeetCode 2100 - Find Good Days to Rob the Bank

The problem asks us to find all days that are "good" for robbing a bank based on the number of guards on duty over a period of days.

leetcodemediumarraydynamic-programmingprefix-sum
LeetCode 3259 - Maximum Energy Boost From Two Drinks

This problem is asking you to plan the consumption of two energy drinks over n hours to maximize the total energy boost. Each drink has a known energy contribution per hour, given by two arrays, energyDrinkA and energyDrinkB. You can drink only one energy drink per hour.

leetcodemediumarraydynamic-programming
LeetCode 3095 - Shortest Subarray With OR at Least K I

The problem asks us to find the shortest subarray within a given array nums such that the bitwise OR of all elements in that subarray is at least k. A subarray is any contiguous sequence of elements in nums.

leetcodeeasyarraybit-manipulationsliding-window
LeetCode 2132 - Stamping the Grid

In this problem, we are given a binary matrix called grid. Every cell contains either: - 0, meaning the cell is empty - 1, meaning the cell is blocked or occupied We are also given a rectangular stamp with dimensions: - stampHeight - stampWidth The goal is to determine whether…

leetcodehardarraygreedymatrixprefix-sum
LeetCode 2856 - Minimum Array Length After Pair Removals

This problem gives us a sorted integer array nums in non-decreasing order. We may repeatedly remove pairs of elements under one important rule: for a chosen pair (i, j), the values must satisfy nums[i] < nums[j].

leetcodemediumarrayhash-tabletwo-pointersbinary-searchgreedycounting
LeetCode 2925 - Maximum Score After Applying Operations on a Tree

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

leetcodemediumdynamic-programmingtreedepth-first-search
LeetCode 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
CF 226E - Noble Knight's Path

In this problem, we are asked to simulate a sequence of events in a feudal hierarchy represented as a tree. Each feudal owns a castle, and except for the king, each feudal reports to exactly one superior.

codeforcescompetitive-programmingdata-structurestrees
LeetCode 2629 - Function Composition

This problem asks us to implement function composition. We are given an array of functions and must return a new function that combines all of them into a single callable function.

leetcodeeasy
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 3171 - Find Subarray With Bitwise OR Closest to K

The problem asks us to find a subarray within a given array nums such that the absolute difference between the integer k and the bitwise OR of the subarray elements is minimized.

leetcodehardarraybinary-searchbit-manipulationsegment-tree
LeetCode 2595 - Number of Even and Odd Bits

The problem asks us to analyze the binary representation of a positive integer n and count how many 1 bits appear at even indices and how many appear at odd indices. Bit positions are counted from right to left, starting at index 0.

leetcodeeasybit-manipulation
LeetCode 1872 - Stone Game VIII

The problem describes a two-player turn-based game between Alice and Bob with a row of stones, each having an integer value.

leetcodehardarraymathdynamic-programmingprefix-sumgame-theory
LeetCode 2647 - Color the Triangle Red

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

leetcodehardarraymath
CF 166A - Rank List

We are given the final results of a programming contest. Each team has two values attached to it: how many problems it solved and its total penalty time. The ranking rule is the standard ICPC-style ordering. A team ranks higher if it solved more problems.

codeforcescompetitive-programmingbinary-searchimplementationsortings
LeetCode 3365 - Rearrange K Substrings to Form Target String

This problem asks whether it is possible to rearrange k contiguous equal-length substrings of a string s to form another string t, given that s and t are anagrams.

leetcodemediumhash-tablestringsorting
LeetCode 2652 - Sum Multiples

The problem requires calculating the sum of all integers from 1 up to a given positive integer n that are divisible by 3, 5, or 7. In simpler terms, we need to consider each number in the range [1, n] and check if it is a multiple of any of these three numbers.

leetcodeeasymath
LeetCode 3391 - Design a 3D Binary Matrix with Efficient Layer Tracking

The problem asks us to design a data structure that manages a 3D binary matrix of size n x n x n. Every cell initially contains 0, and we must support three operations efficiently: 1. setCell(x, y, z) sets a specific cell to 1. 2.

leetcodemediumarrayhash-tabledesignheap-(priority-queue)matrixordered-set
CF 152E - Garden

We have a rectangular grid where every cell has a cost, the number of flowers destroyed if we pave that cell with concrete. Among all cells, there are up to seven special cells containing important buildings.

codeforcescompetitive-programmingbitmasksdpgraphstrees
LeetCode 2318 - Number of Distinct Roll Sequences

The problem is asking us to compute the total number of distinct sequences of dice rolls of length n that satisfy two constraints: the greatest common divisor (GCD) of any two consecutive rolls must be 1, and any repeated value in the sequence must be separated by at least two…

leetcodeharddynamic-programmingmemoization
LeetCode 2948 - Make Lexicographically Smallest Array by Swapping Elements

The problem asks us to transform a given array of positive integers nums into its lexicographically smallest form by performing a specific swap operation any number of times.

leetcodemediumarrayunion-findsorting
LeetCode 2992 - Number of Self-Divisible Permutations

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

leetcodemediumarraymathdynamic-programmingbacktrackingbit-manipulationnumber-theorybitmask
LeetCode 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
LeetCode 2581 - Count Number of Possible Root Nodes

This problem gives us an undirected tree with n nodes and a list of directed parent-child guesses. Each guess claims that one node is the parent of another node when the tree is rooted in some way. The important detail is that the tree itself is undirected.

leetcodehardarrayhash-tabledynamic-programmingtreedepth-first-search
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 2680 - Maximum OR

In this problem, we are given an integer array nums and an integer k. We may perform at most k operations, where each operation selects one element and multiplies it by 2. Multiplying by 2 in binary is equivalent to shifting all bits one position to the left.

leetcodemediumarraygreedybit-manipulationprefix-sum
LeetCode 3223 - Minimum Length of String After Operations

The problem asks us to repeatedly remove characters from a string based on a specific rule. Specifically, for any character s[i] in the string, we can remove the nearest occurrence of the same character to the left of i and the nearest occurrence to the right of i.

leetcodemediumhash-tablestringcounting
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 1877 - Minimize Maximum Pair Sum in Array

The problem asks us to pair elements in an array of even length such that the largest sum among all pairs is minimized. In simpler terms, imagine we have a collection of numbers and we want to form pairs of two numbers each. Each number can only belong to one pair.

leetcodemediumarraytwo-pointersgreedysorting
CF 420E - Playing the ball

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

codeforcescompetitive-programminggeometry
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 3239 - Minimum Number of Flips to Make Binary Grid Palindromic I

You are given a binary matrix grid with m rows and n columns. Every cell contains either 0 or 1. A row is considered palindromic if reading it from left to right gives the same sequence as reading it from right to left.

leetcodemediumarraytwo-pointersmatrix
CF 151B - Phone Numbers

Each friend has a phone book containing numbers written in the format XX-XX-XX. Every phone number belongs to exactly one of three categories. A taxi number uses the same digit everywhere. Examples are 11-11-11 or 55-55-55.

codeforcescompetitive-programmingimplementationstrings
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 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 2315 - Count Asterisks

The problem gives us a string s containing lowercase English letters, vertical bars '|', and asterisks ''. The key rule is that every two consecutive vertical bars form a pair. Any asterisk located between the two bars of a pair must be ignored when counting.

leetcodeeasystring
CF 141A - Amusing Joke

We are given three uppercase strings. The first two strings are the names written on the door, and the third string is the pile of letters found the next morning after somebody mixed everything together.

codeforcescompetitive-programmingimplementationsortingsstrings
LeetCode 3325 - Count Substrings With K-Frequency Characters I

The problem asks us to count all substrings of a given string s such that at least one character in the substring appears at least k times. In simpler terms, for every substring we consider, we check whether there is any character that has frequency greater than or equal to k.

leetcodemediumhash-tablestringsliding-window
LeetCode 2069 - Walking Robot Simulation II

The problem describes a simulation of a robot moving on a rectangular grid defined by width x height. The robot starts at the bottom-left corner (0, 0) facing East and moves in discrete steps.

leetcodemediumdesignsimulation
LeetCode 3262 - Find Overlapping Shifts

The problem requires counting overlapping shifts for each employee from a database table called EmployeeShifts. Each row in this table represents a single shift worked by an employee, with a starttime and an endtime.

leetcodemediumdatabase
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
CF 420B - Online Meeting

We have a meeting log for a team of developers where each log entry records either a user logging in or logging out. The log may start or end in the middle of the meeting, so we do not know who was online before the first recorded message.

codeforcescompetitive-programmingimplementation
LeetCode 2624 - Snail Traversal

The problem asks us to take a 1D array of integers and convert it into a 2D matrix of specified dimensions, rowsCount and colsCount, following a snail traversal order by columns.

leetcodemedium
LeetCode 3246 - Premier League Table Ranking

This problem asks us to generate a league standings table from a database table named TeamStats. Each row in the table represents a football team and stores how many matches the team has played, won, drawn, and lost.

leetcodeeasydatabase
LeetCode 3107 - Minimum Operations to Make Median of Array Equal to K

The problem asks us to transform an integer array so that its median becomes exactly k, using the minimum number of operations. In one operation, we may either increase or decrease any single element by 1. The median is defined after sorting the array in non-decreasing order.

leetcodemediumarraygreedysorting
CF 311C - Fetch the Treasure

We have a linear arrangement of h cells, numbered from 1 to h. Some of these cells contain treasures, each with a positive dollar value.

codeforcescompetitive-programmingbrute-forcedata-structuresgraphsshortest-paths
LeetCode 2755 - Deep Merge of Two Objects

Here is the complete technical solution guide for LeetCode 2755 following your requested format. The problem asks us to deep merge two JSON values, obj1 and obj2. The merging rules depend on the type of the values at each position in the objects or arrays.

leetcodemedium
CF 241B - Friends

We have an array of friend attractiveness values. Every unordered pair of distinct friends produces one possible picture, and the value of that picture is the xor of the two attractiveness values.

codeforcescompetitive-programmingbinary-searchbitmasksdata-structuresmath
CF 417C - Football

We are asked to construct a complete record of matches between n teams, where every match has a winner and a loser, and no pair of teams plays more than once.

codeforcescompetitive-programmingconstructive-algorithmsgraphsimplementation
LeetCode 2620 - Counter

The problem is asking us to implement a simple counter function with a closure-like behavior. Given an integer n, we need to return a function counter() that, when called the first time, returns n, and then increments the returned value by one for every subsequent call.

leetcodeeasy
CF 412D - Giving Awards

We have a directed graph of debts. An edge a - b means employee a owes money to employee b. We must arrange all employees in a sequence such that for every pair of consecutive employees (x, y) in the sequence, there is no edge x - y.

codeforcescompetitive-programmingdfs-and-similar
LeetCode 2182 - Construct String With Repeat Limit

The problem asks us to construct a string from the characters of a given string s under a specific constraint: no character can appear more than repeatLimit times consecutively.

leetcodemediumhash-tablestringgreedyheap-(priority-queue)counting