brain

tamnd's digital brain — notes, problems, research

43815 notes

LeetCode 2544 - Alternating Digit Sum

The problem asks us to compute an alternating sum of the digits of a positive integer. The alternation starts from the most significant digit, which always has a positive sign. Every following digit flips the sign from the previous one.

leetcodeeasymath
CF 148E - Porcelain

We have several shelves of porcelain items. Inside one shelf, the items form a line, and at any moment we may only remove the current leftmost item or the current rightmost item. After removing one item, the next item on that side becomes accessible.

codeforcescompetitive-programmingdp
LeetCode 2698 - Find the Punishment Number of an Integer

The problem asks us to compute a special value called the punishment number for a given integer n. For every integer i in the range [1, n], we square the number and examine the decimal representation of i i.

leetcodemediummathbacktracking
LeetCode 3397 - Maximum Number of Distinct Elements After Operations

The problem asks us to maximize the number of distinct elements in an integer array nums by performing a limited set of operations. Each element can be modified at most once by adding an integer in the range [-k, k].

leetcodemediumarraygreedysorting
LeetCode 2861 - Maximum Number of Alloys

This guide will be quite long because you requested a comprehensive reference document with multiple sections, detailed walkthroughs, complete Python and Go implementations, worked examples, test cases, edge cases, and complexity analysis.

leetcodemediumarraybinary-search
LeetCode 2048 - Next Greater Numerically Balanced Number

The problem asks us to find the smallest integer strictly greater than n such that the number is numerically balanced. A number is numerically balanced when every digit that appears in the number appears exactly as many times as its value.

leetcodemediumhash-tablemathbacktrackingcountingenumeration
LeetCode 2575 - Find the Divisibility Array of a String

The problem gives us a numeric string word and an integer m. For every prefix of the string, we must determine whether that prefix represents a number divisible by m. A prefix word[0...i] means the substring starting at index 0 and ending at index i, inclusive.

leetcodemediumarraymathstring
LeetCode 3215 - Count Triplets with Even XOR Set Bits II

The problem asks us to count the number of triplets (a[i], b[j], c[k]) from three integer arrays a, b, and c such that the bitwise XOR of the three numbers has an even number of set bits (bits equal to 1 in binary representation).

leetcodemediumarraybit-manipulation
LeetCode 3094 - Guess the Number Using Bitwise Questions II

Before I write the full guide, I want to confirm one detail: for LeetCode 3094 - Guess the Number Using Bitwise Questions II, there are no public input/output examples in the problem statement because it is an interactive problem.

leetcodemediumbit-manipulationinteractive
LeetCode 2217 - Find Palindrome With Fixed Length

The problem asks us to find the k-th smallest positive palindrome of a fixed length for multiple queries. Specifically, we are given an array queries where each element indicates the position of a palindrome we need to find, and an integer intLength which specifies the number…

leetcodemediumarraymath
CF 187C - Weak Memory

We have an undirected graph representing intersections and roads inside the park. Some intersections contain volunteers. PMP starts at intersection s, and the bus station is at intersection t. PMP has weak memory.

codeforcescompetitive-programmingdfs-and-similardsu
LeetCode 2406 - Divide Intervals Into Minimum Number of Groups

The problem gives us a list of inclusive intervals, where each interval is represented as [left, right]. We must divide all intervals into groups such that no two intervals inside the same group intersect. The important detail is that the intervals are inclusive.

leetcodemediumarraytwo-pointersgreedysortingheap-(priority-queue)prefix-sum
LeetCode 2822 - Inversion of Object

This problem asks us to invert the relationship between keys and values in a JSON object or array. The input can be either: - A JSON object, where keys are strings and values are strings. - A JSON array, where indices act as keys and elements are strings.

leetcodeeasy
CF 246E - Blood Cousins Return

We are given a rooted forest describing family relations. Every person has a name and at most one parent. Multiple roots are allowed because some people may have no ancestor at all.

codeforcescompetitive-programmingbinary-searchdata-structuresdfs-and-similardpsortings
LeetCode 3253 - Construct String with Minimum Cost (Easy)

=== 1996-N5 === Origin: ROM Let denote the set of nonnegative integers. Find a bijective function from into such that for all , We first observe that the given functional equation is equivalent to This gives us the idea of introducing a function defined as By the above…

leetcodemedium
LeetCode 2747 - Count Zero Request Servers

This problem asks us to count servers that did not receive any requests within a certain time window for multiple queries. You are given n servers, each with a unique ID from 1 to n.

leetcodemediumarrayhash-tablesliding-windowsorting
LeetCode 1968 - Array With Elements Not Equal to Average of Neighbors

The problem asks us to rearrange a distinct integer array so that no element is equal to the average of its neighbors. The input is a zero-indexed array nums of length at least 3, and all elements are guaranteed to be distinct.

leetcodemediumarraygreedysorting
CF 229A - Shifts

We have a binary matrix where each row can be rotated cyclically. A left rotation moves every element one position left and wraps the first element to the end. A right rotation does the opposite.

codeforcescompetitive-programmingbrute-forcetwo-pointers
LeetCode 3328 - Find Cities in Each State II

The problem gives us a database table named cities, where each row contains a state name and a city name. The pair (state, city) is guaranteed to be unique, which means the same city will not appear twice for the same state. We must generate a report for qualifying states.

leetcodemediumdatabase
LeetCode 3241 - Time Taken to Mark All Nodes

We are given an undirected tree with n nodes. A tree is a connected graph with exactly n - 1 edges and no cycles. Each node has a special propagation delay determined entirely by its parity: - Odd-numbered nodes become marked 1 time unit after one of their neighbors is marked.

leetcodeharddynamic-programmingtreedepth-first-searchgraph-theory
LeetCode 2422 - Merge Operations to Turn Array Into a Palindrome

The problem asks us to transform a given array of positive integers into a palindrome using the minimum number of operations, where each operation consists of taking two adjacent elements and replacing them with their sum.

leetcodemediumarraytwo-pointersgreedy
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
CF 265B - Roadside Trees (Simplified Edition)

We have a sequence of trees along a straight street. Each tree has a certain height, and on top of each tree is a nut that Squirrel Liss wants to eat. Liss starts at the base of the first tree.

codeforcescompetitive-programminggreedyimplementation
LeetCode 2397 - Maximum Rows Covered by Columns

This problem asks us to maximize the number of rows covered in a binary matrix after selecting exactly numSelect columns. Each row is covered if all 1s in that row are located in the selected columns, or if the row contains only 0s.

leetcodemediumarraybacktrackingbit-manipulationmatrixenumeration
LeetCode 1974 - Minimum Time to Type Word Using Special Typewriter

The problem describes a circular typewriter containing all lowercase English letters from 'a' to 'z'. A pointer moves around this circular arrangement, and initially the pointer starts at 'a'. To type a character, the pointer must currently point at that character.

leetcodeeasystringgreedy
LeetCode 2803 - Factorial Generator

This problem asks us to implement a generator that produces the factorial sequence up to a given integer n. Recall that the factorial of a positive integer is defined as: Additionally, by definition: The generator should not return only the final factorial value.

leetcodeeasy
LeetCode 2095 - Delete the Middle Node of a Linked List

The problem gives us the head of a singly linked list and asks us to delete the middle node. The definition of the middle node is based on 0-based indexing. If the list has n nodes, then the middle node is the node at index ⌊n / 2⌋.

leetcodemediumlinked-listtwo-pointers
LeetCode 1875 - Group Employees of the Same Salary

This is a SQL database problem where we need to group employees into teams based on salary. The important detail is that a team is defined entirely by salary, meaning every employee in a team must have exactly the same salary, and all employees with the same salary must belong…

leetcodemediumdatabase
LeetCode 1921 - Eliminate Maximum Number of Monsters

This problem asks us to determine how many monsters we can eliminate before any one of them reaches the city. Each monster starts at some distance from the city and moves toward it at a constant speed.

leetcodemediumarraygreedysorting
LeetCode 2654 - Minimum Number of Operations to Make All Array Elements Equal to 1

The problem gives us an array of positive integers, nums. In one operation, we may choose two adjacent elements, nums[i] and nums[i+1], and replace either one of them with the greatest common divisor, gcd, of the pair.

leetcodemediumarraymathnumber-theory
LeetCode 2291 - Maximum Profit From Trading Stocks

The problem gives us two arrays, present and future, where each index represents a stock. The value present[i] is the price of buying the i-th stock today, while future[i] is the price at which the same stock can be sold one year later.

leetcodemediumarraydynamic-programming
LeetCode 2056 - Number of Valid Move Combinations On Chessboard

The problem asks us to calculate the total number of valid move combinations for a small set of chess pieces (up to four) on an 8 x 8 chessboard. Each piece-rook, bishop, or queen-can move according to standard chess rules, but only along paths defined by the piece's movement.

leetcodehardarraystringbacktrackingsimulation
LeetCode 3395 - Subsequences with a Unique Middle Mode I

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

leetcodehardarrayhash-tablemathcombinatorics
LeetCode 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 2054 - Two Best Non-Overlapping Events

The problem gives us a list of events, where each event is represented as: Each event occupies an inclusive time interval from startTime to endTime. If we attend that event, we earn value points. We are allowed to attend at most two events, but the chosen events must not overlap.

leetcodemediumarraybinary-searchdynamic-programmingsortingheap-(priority-queue)
LeetCode 2896 - Apply Operations to Make Two Strings Equal

We are given two binary strings, s1 and s2, of the same length n, along with a positive integer x. Our goal is to transform s1 into s2 using the minimum possible cost. We are allowed to perform two kinds of operations: 1. Choose any two positions i and j, then flip both bits.

leetcodemediumstringdynamic-programming
LeetCode 3247 - Number of Subsequences with Odd Sum

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

leetcodemediumarraymathdynamic-programmingcombinatorics
LeetCode 2830 - Maximize the Profit as the Salesman

This problem gives us n houses arranged on a number line and a collection of purchase offers. Each offer is represented as [start, end, gold], meaning a buyer wants to purchase every house in the inclusive range [start, end] and is willing to pay gold units of gold.

leetcodemediumarrayhash-tablebinary-searchdynamic-programmingsorting
CF 424A - Squats

We are given a row on size, showing the algorithm handles boundary constraints uniformly.

codeforcescompetitive-programmingimplementation
LeetCode 2176 - Count Equal and Divisible Pairs in an Array

The problem gives us a 0-indexed integer array nums and an integer k. We need to count how many pairs of indices (i, j) satisfy all of the following conditions: 1. 0 <= i < j < n 2. nums[i] == nums[j] 3.

leetcodeeasyarray
CF 432A - Choosing Teams

We are given a set of students at a university, each with a record of how many times they have already participated in the ACM ICPC world championship.

codeforcescompetitive-programminggreedyimplementationsortings
LeetCode 2501 - Longest Square Streak in an Array

The problem asks us to identify the longest square streak in an array of integers nums. A square streak is a subsequence of at least length 2 where, after sorting, every element is the square of the previous element. In other words, if the sorted subsequence is [x1, x2, ...

leetcodemediumarrayhash-tablebinary-searchdynamic-programmingsorting
LeetCode 3061 - Calculate Trapping Rain Water

This problem asks us to compute how much rainwater can be trapped between vertical bars after rainfall. The bars are represented in a database table named Heights, where each row contains an id and a height.

leetcodeharddatabase
LeetCode 2987 - Find Expensive Cities

This problem provides a database table named Listings that contains information about home listings. Each row represents a single home listing and contains three fields: - listingid, a unique identifier for the listing - city, the city where the home is located - price, the…

leetcodeeasydatabase
LeetCode 2299 - Strong Password Checker II

The problem asks us to determine whether a given password string satisfies a set of security requirements. We are given a single string, password, and we must return true if every condition is satisfied, otherwise return false.

leetcodeeasystring
LeetCode 1954 - Minimum Garden Perimeter to Collect Enough Apples

The problem describes an infinite two dimensional grid where every integer coordinate (i, j) contains an apple tree.

leetcodemediummathbinary-search
LeetCode 3022 - Minimize OR of Remaining Elements Using Operations

The problem presents an array nums of non-negative integers and an integer k. You are allowed to perform at most k operations, where each operation merges two adjacent elements using the bitwise AND operator.

leetcodehardarraygreedybit-manipulation
LeetCode 1896 - Minimum Cost to Change the Final Value of Expression

This problem gives us a boolean expression containing only: - '0' and '1' - binary operators '&' and '|' - parentheses The expression is guaranteed to be valid, which means every operator has valid operands and every parenthesis is properly matched.

leetcodehardmathstringdynamic-programmingstack
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
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 2598 - Smallest Missing Non-negative Integer After Operations

That is a long, structured technical guide with multiple required sections and two full implementations. To keep the quality high and follow your formatting rules exactly, I will provide it in a single comprehensive response.

leetcodemediumarrayhash-tablemathgreedy
CF 424B - Megacity

Codeforces 424B: Megacity

codeforcescompetitive-programmingbinary-searchgreedyimplementationsortings
CF 305E - Playing with String

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

codeforcescompetitive-programminggames
CF 216A - Tiling with Hexagons

The floor is made from unit hexagonal tiles, and the whole hall itself forms a larger hexagon. The six sides of the hall contain a, b, c, a, b, c tiles respectively as we walk around the boundary.

codeforcescompetitive-programmingimplementationmath
LeetCode 3123 - Find Edges in Shortest Paths

The problem gives us an undirected weighted graph with n nodes and m edges. Each edge connects two nodes and has a positive weight. We need to determine which edges belong to at least one shortest path from node 0 to node n - 1.

leetcodeharddepth-first-searchbreadth-first-searchgraph-theoryheap-(priority-queue)shortest-path
LeetCode 2846 - Minimum Edge Weight Equilibrium Queries in a Tree

You are given an undirected weighted tree with n nodes. Since the graph is a tree, there is exactly one simple path between any two nodes. Each edge has a weight between 1 and 26. For every query [a, b], we look at the unique path from node a to node b.

leetcodehardarraydynamic-programmingbit-manipulationtreedepth-first-search
LeetCode 1855 - Maximum Distance Between a Pair of Values

You are given two integer arrays, nums1 and nums2, and both arrays are sorted in non-increasing order. That means the values either stay the same or decrease as we move from left to right. A pair of indices (i, j) is considered valid if two conditions are satisfied: 1. i <= j 2.

leetcodemediumarraytwo-pointersbinary-search
LeetCode 2348 - Number of Zero-Filled Subarrays

The problem asks us to count the number of contiguous subarrays in an integer array nums that consist entirely of zeros. A subarray is defined as any consecutive sequence of elements from the original array.

leetcodemediumarraymath
LeetCode 2674 - Split a Circular Linked List

The problem asks us to take a circular linked list of positive integers and split it into two separate circular linked lists. The first list should contain the first half of the nodes, rounded up (ceil(length / 2)), and the second list should contain the remaining nodes.

leetcodemediumlinked-listtwo-pointers
LeetCode 3346 - Maximum Frequency of an Element After Performing Operations I

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

leetcodemediumarraybinary-searchsliding-windowsortingprefix-sum
LeetCode 2292 - Products With Three or More Orders in Two Consecutive Years

This problem provides a table named Orders, where each row represents a single purchase event. Every order contains an orderid, a productid, the purchased quantity, and the purchasedate. The goal is to identify all products that satisfy two conditions simultaneously: 1.

leetcodemediumdatabase
LeetCode 2090 - K Radius Subarray Averages

The problem asks us to compute a special average for every index in the array. For each position i, we want to look at a subarray centered at i with radius k. That means we include all elements from index i - k through i + k, inclusive.

leetcodemediumarraysliding-window
CF 305C - Ivan and Powers of Two

We are given a sorted array of exponents. Instead of the exponents themselves, Ivan writes the corresponding powers of two on paper: $$2^{a1}, 2^{a2}, dots, 2^{an}$$ We may add more numbers, but every added number must also be a power of two.

codeforcescompetitive-programminggreedyimplementation
LeetCode 1866 - Number of Ways to Rearrange Sticks With K Sticks Visible

The problem gives us n sticks with unique lengths from 1 to n. We must arrange these sticks in some order so that exactly k sticks are visible when looking from the left side. A stick is visible if every stick before it is shorter.

leetcodehardmathdynamic-programmingcombinatorics
LeetCode 1873 - Calculate Special Bonus

This problem asks us to write an SQL query that calculates a special bonus for every employee in the Employees table.

leetcodeeasydatabase
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
CF 354E - Lucky Number Representation

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

codeforcescompetitive-programmingconstructive-algorithmsdfs-and-similardp
CF 169A - Chores

We have a list of chore difficulties. Vasya must receive exactly b chores whose difficulty is at most x, while Petya must receive exactly a chores whose difficulty is strictly greater than x. The value x must be an integer. We need to count how many integers satisfy the split.

codeforcescompetitive-programmingsortings
LeetCode 3286 - Find a Safe Walk Through a Grid

The problem requires determining whether there exists a path from the top-left corner (0, 0) to the bottom-right corner (m - 1, n - 1) in a binary m x n matrix grid, while maintaining a health value greater than or equal to 1.

leetcodemediumarraybreadth-first-searchgraph-theoryheap-(priority-queue)matrixshortest-path
LeetCode 2936 - Number of Equal Numbers Blocks

The problem is asking us to count the number of maximal contiguous blocks of equal numbers in a very large array nums. A block is maximal if it contains all consecutive occurrences of the same number, and numbers are guaranteed to appear in consecutive segments, i.e.

leetcodemediumarraybinary-searchinteractive
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 1997 - First Day Where You Have Been in All the Rooms

The problem describes a scenario where you visit a sequence of n rooms, starting from room 0 on day 0. The order of subsequent visits is determined by a rule that depends on how many times you have visited the current room.

leetcodemediumarraydynamic-programming
LeetCode 3256 - Maximum Value Sum by Placing Three Rooks I

We are given an m x n matrix called board, where each cell contains an integer value. We must place exactly three rooks on the board. A rook attacks every square in the same row and the same column.

leetcodehardarraydynamic-programmingmatrixenumeration
LeetCode 2688 - Find Active Users

The problem gives us a database table named Users. Each row represents a purchase made by a user. The columns include: - userid, the identifier of the user - item, the purchased product - createdat, the purchase timestamp - amount, the purchase value The table may contain…

leetcodemediumdatabase
LeetCode 2610 - Convert an Array Into a 2D Array With Conditions

The problem asks us to transform a one-dimensional integer array nums into a two-dimensional array (a list of lists) while satisfying three specific conditions. First, every element from nums must appear in the 2D array exactly as many times as it appears in the original array.

leetcodemediumarrayhash-table
LeetCode 2777 - Date Range Generator

The problem asks us to generate a sequence of dates starting from a given start date and ending at a given end date, incrementing by a fixed number of days defined by step.

leetcodemedium
LeetCode 2465 - Number of Distinct Averages

The problem requires calculating the number of distinct averages generated from a sequence of numbers using a specific process. The input is an integer array nums of even length.

leetcodeeasyarrayhash-tabletwo-pointerssorting
CF 426B - Sereja and Mirroring

We start with some small matrix b. One mirroring operation doubles its height. The top half stays unchanged, and the bottom half becomes the rows of the top half written in reverse order.

codeforcescompetitive-programmingimplementation
LeetCode 3351 - Sum of Good Subsequences

This problem asks us to compute the sum of all good subsequences in a given integer array nums. A subsequence is any sequence derived from nums by deleting zero or more elements without changing the order of the remaining elements.

leetcodehardarrayhash-tabledynamic-programming
CF 173D - Deputies

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

codeforcescompetitive-programmingconstructive-algorithmsgraphsgreedyimplementation
LeetCode 2042 - Check if Numbers Are Ascending in a Sentence

The problem asks us to analyze a sentence represented as a string s and determine whether all numbers embedded in the sentence are strictly increasing from left to right.

leetcodeeasystring
LeetCode 2813 - Maximum Elegance of a K-Length Subsequence

The problem presents a 0-indexed 2D array items of length n, where each element represents an item with two values: a profit and a category. You are asked to select exactly k items to form a subsequence. A subsequence preserves the original order of items but can skip elements.

leetcodehardarrayhash-tablestackgreedysortingheap-(priority-queue)
LeetCode 3159 - Find Occurrences of an Element in an Array

The problem gives us three inputs: - An integer array nums - An integer array queries - An integer x We need to answer each query independently. A query asks for the index of the kth occurrence of the value x inside the array nums.

leetcodemediumarrayhash-table
LeetCode 3194 - Minimum Average of Smallest and Largest Elements

The problem gives us an even-length integer array nums. We repeatedly perform the following operation until the array becomes empty: 1. Remove the smallest element. 2. Remove the largest element. 3. Compute their average. 4. Store that average in another array called averages.

leetcodeeasyarraytwo-pointerssorting
LeetCode 2117 - Abbreviating the Product of a Range

We are given two integers, a and b. The task is deceptively small because the entire original statement is represented only by a picture.

leetcodehardmathnumber-theory
CF 191A - Dynasty Puzzles

We are given a list of abbreviated king names in chronological order. Each name is a lowercase string. We may choose some of these names to form a dynasty, while preserving their original order. A valid dynasty must satisfy two conditions.

codeforcescompetitive-programmingdp
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 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
CF 207A1 - Beaver's Calculator 1.0

We are given several scientists, each producing a sequence of computational tasks. Every task has a fixed resource requirement, and within each scientist’s list the tasks must be executed in the given order.

codeforcescompetitive-programminggreedy
CF 204D - Little Elephant and Retro Strings

We are given a string consisting of three possible characters: fixed black cells, fixed white cells, and unknown cells that we are free to assign either color.

codeforcescompetitive-programmingdp
LeetCode 2075 - Decode the Slanted Ciphertext

The problem requires decoding a string that was encoded using a slanted transposition cipher. In this cipher, the original text is written diagonally in a grid with a fixed number of rows.

leetcodemediumstringsimulation
CF 440B - Balancer

We are given a row of matchboxes, each containing some number of matches. The total number of matches is divisible by the number of boxes, so there exists a target configuration where every box ends up holding exactly the same number.

codeforcescompetitive-programminggreedyimplementation
LeetCode 2039 - The Time When the Network Becomes Idle

This problem involves a network of servers where server 0 is the master and all other servers are data servers. Each data server initially sends a message to the master, and the master instantly responds upon receiving the message.

leetcodemediumarraybreadth-first-searchgraph-theory
LeetCode 1975 - Maximum Matrix Sum

The problem gives an n x n integer matrix and allows an operation where we pick any two adjacent cells (sharing a side) and multiply both values by -1.

leetcodemediumarraygreedymatrix
CF 241A - Old Peykan

We are asked to model a journey along a straight line of cities connected by one-way roads, where a car travels at a constant speed of one kilometer per hour and consumes one liter of fuel per kilometer.

codeforcescompetitive-programminggreedy
LeetCode 2871 - Split Array Into Maximum Number of Subarrays

The problem is asking us to split a given array of non-negative integers into contiguous subarrays in a way that maximizes the number of subarrays, while minimizing the sum of their bitwise AND scores.

leetcodemediumarraygreedybit-manipulation
LeetCode 3057 - Employees Project Allocation

This problem asks us to identify employees whose assigned project workload is greater than the average workload of employees within their own team. We are given two database tables: The Project table stores information about project assignments.

leetcodeharddatabase
CF 165B - Burning Midnight Oil

Vasya has to write at least n lines of code during one night. He starts with productivity v, meaning he writes v lines before the first tea break. After every break, his productivity drops by a factor of k, using integer division.

codeforcescompetitive-programmingbinary-searchimplementation
CF 241G - Challenging Balloons

We have a row of balloons placed at increasing positions on a line. Each balloon has a pressure endurance, which limits how large its radius can grow. We inflate balloons sequentially from left to right.

codeforcescompetitive-programmingconstructive-algorithms
LeetCode 2954 - Count the Number of Infection Sequences

This problem asks us to compute the number of valid infection sequences in a line of n people, where some people are initially infected. The array sick represents the indices of people who are already infected at the start.

leetcodehardarraymathcombinatorics