brain

tamnd's digital brain — notes, problems, research

43815 notes

LeetCode 2295 - Replace Elements in an Array

The problem asks us to perform a series of replacement operations on an array of distinct integers. Specifically, we have an initial array nums containing n distinct positive integers. We are also given m operations, each consisting of a pair [oldValue, newValue].

leetcodemediumarrayhash-tablesimulation
LeetCode 2434 - Using a Robot to Print the Lexicographically Smallest String

In this problem, we are given a string s and a robot that manages another temporary string t. Initially, t is empty. The robot repeatedly performs one of two allowed operations: First, it may remove the first character from s and append it to the end of t.

leetcodemediumhash-tablestringstackgreedy
LeetCode 1956 - Minimum Time For K Virus Variants to Spread

The problem describes multiple virus variants spreading across an infinite 2D grid. Each virus starts from its own origin point on day 0.

leetcodehardarraymathbinary-searchgeometryenumeration
LeetCode 3237 - Alt and Tab Simulation

The problem asks us to simulate the behavior of switching between open windows using the classic Alt + Tab operation. We are given an array called windows, which represents the current ordering of open windows.

leetcodemediumarrayhash-tablesimulation
LeetCode 2088 - Count Fertile Pyramids in a Land

The problem gives us a binary matrix where each cell represents a piece of land. A value of 1 means the land is fertile, while 0 means barren. We need to count every valid pyramidal plot and inverse pyramidal plot formed entirely from fertile cells.

leetcodehardarraydynamic-programmingmatrix
LeetCode 2964 - Number of Divisible Triplet Sums

The problem gives us an integer array nums and an integer d. We must count how many triplets of indices (i, j, k) satisfy two conditions: 1. The indices are strictly increasing, meaning i < j < k. 2. The sum of the corresponding elements is divisible by d.

leetcodemediumarrayhash-table
LeetCode 2096 - Step-By-Step Directions From a Binary Tree Node to Another

The problem gives us a binary tree where every node contains a unique value from 1 to n. We are also given two node values: - startValue, the node where the path begins - destValue, the node where the path must end We must return the shortest sequence of directions needed to…

leetcodemediumstringtreedepth-first-searchbinary-tree
LeetCode 3359 - Find Sorted Submatrices With Maximum Element at Most K

We are given a matrix grid with m rows and n columns, along with an integer k. The task is to count how many rectangular submatrices satisfy two conditions simultaneously: 1. Every value inside the submatrix must be at most k. 2.

leetcodehardarraystackmatrixmonotonic-stack
LeetCode 3377 - Digit Operations to Make Two Integers Equal

The problem asks us to transform one integer n into another integer m by repeatedly modifying individual digits of n. At each step, we can increase a digit that is not 9 or decrease a digit that is not 0.

leetcodemediummathgraph-theoryheap-(priority-queue)number-theoryshortest-path
LeetCode 1804 - Implement Trie II (Prefix Tree)

This problem asks us to implement a Trie data structure, also known as a prefix tree, which is designed to store strings efficiently in a way that allows fast lookups and prefix queries. We are required to implement the following operations: 1.

leetcodemediumhash-tablestringdesigntrie
LeetCode 3396 - Minimum Number of Operations to Make Elements in Array Distinct

The problem gives us an integer array nums, and our goal is to make all remaining elements distinct. The only allowed operation is removing exactly 3 elements from the beginning of the array. If fewer than 3 elements remain, we remove everything that is left.

leetcodeeasyarrayhash-table
CF 246A - Buggy Sorting

We are given only a single integer $n$, and we must construct an array of length $n$ that either breaks a very specific sorting procedure or prove that no such array exists.

codeforcescompetitive-programmingconstructive-algorithmsgreedysortings
CF 262B - Roma and Changing Signs

Codeforces 262B: Roma and Changing Signs

codeforcescompetitive-programminggreedy
CF 417E - Square Table

We are asked to fill an $n times m$ grid with positive integers not exceeding $10^8$. The constraint is not about individual cells but about structure: for every row and every column, if we square all numbers in that line and sum them, the result must itself be a perfect square.

codeforcescompetitive-programmingconstructive-algorithmsmathprobabilities
LeetCode 2786 - Visit Array Positions to Maximize Score

The problem presents a 0-indexed array nums of integers and a positive integer x. You start at the first element, nums[0], and can move to any subsequent position j where j i. For each element you visit, you accumulate its value as part of your score.

leetcodemediumarraydynamic-programming
LeetCode 3294 - Convert Doubly Linked List to Array II

This problem gives us a pointer to an arbitrary node inside a doubly linked list. Unlike many linked list problems, we are not guaranteed to receive the head of the list. Instead, we may receive any node somewhere in the middle or even the tail.

leetcodemediumarraylinked-listdoubly-linked-list
CF 215A - Bicycle Chain

We have two sets of bicycle gears. The front gears are attached to the pedals, and the rear gears are attached to the back wheel. If the chain connects front gear a[i] to rear gear b[j], the resulting gear ratio is b[j] / a[i].

codeforcescompetitive-programmingbrute-forceimplementation
LeetCode 1884 - Egg Drop With 2 Eggs and N Floors

This problem asks us to determine the minimum number of moves required to identify a critical floor f in a building with n floors, using exactly two eggs. The critical floor f has the following meaning: - Any egg dropped from a floor higher than f will break.

leetcodemediummathdynamic-programming
CF 163D - Large Refrigerator

We need to build a rectangular box with integer side lengths a, b, and c. Its volume must equal a given number V, and among all such integer triples we want the one with minimum surface area.

codeforcescompetitive-programmingbrute-force
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
CF 203A - Two Problems

There are two independent tasks available during a contest that lasts from minute 0 up to minute t minus 1. Each task has a score that decreases linearly with time.

codeforcescompetitive-programmingbrute-forceimplementation
LeetCode 2266 - Count Number of Texts

The problem requires determining how many possible text messages Alice could have sent given a sequence of digit key presses received by Bob. Each digit from '2' to '9' maps to a set of letters on a phone keypad.

leetcodemediumhash-tablemathstringdynamic-programming
LeetCode 2769 - Find the Maximum Achievable Number

The problem gives us two integers, num and t. We are allowed to perform a specific operation at most t times. In one operation, we must simultaneously modify both numbers involved: - Increase or decrease x by 1 - At the same time, increase or decrease num by 1 The goal is to…

leetcodeeasymath
LeetCode 2405 - Optimal Partition of String

The problem asks us to divide a given string s into the minimum number of substrings such that every substring contains only unique characters. In other words, within a single substring, no character may appear more than once.

leetcodemediumhash-tablestringgreedy
LeetCode 2584 - Split the Array to Make Coprime Products

The problem is asking us to find a valid split point in an array nums where the product of elements to the left of the split and the product of elements to the right are coprime. Formally, if we split at index i, the left product is nums[0] nums[1] ...

leetcodehardarrayhash-tablemathnumber-theory
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
LeetCode 2086 - Minimum Number of Food Buckets to Feed the Hamsters

The problem is asking us to place the minimum number of food buckets on empty spaces in a linear arrangement of cells so that all hamsters are fed. Each cell in the string hamsters represents either a hamster ('H') or an empty spot ('.').

leetcodemediumstringdynamic-programminggreedy
CF 205A - Little Elephant and Rozdil

We are given a list of travel times from the town Rozdil to each of n other towns. Each town has a positive integer time, and the towns are numbered from 1 to n. The goal is to find which town has the smallest travel time.

codeforcescompetitive-programmingbrute-forceimplementation
CF 403E - Two Rooted Trees

Codeforces 403E: Two Rooted Trees

codeforcescompetitive-programmingdata-structuresimplementationtrees
CF 163C - Conveyor

We are asked to calculate probabilities for Anton picking up chocolates from a moving conveyor belt. The belt has a straight visible part of length l and loops back under the floor, making the total belt length 2l.

codeforcescompetitive-programmingsortingstwo-pointers
LeetCode 2670 - Find the Distinct Difference Array

The problem asks us to compute the distinct difference array for a given integer array nums. For each index i in the array, we calculate the difference between the number of distinct elements in the prefix nums[0, ...

leetcodeeasyarrayhash-table
LeetCode 2590 - Design a Todo List

This problem asks us to design a small task management system, similar to a lightweight todo application. We need to implement a TodoList class that supports adding tasks, marking tasks as completed, retrieving all pending tasks for a user, and filtering pending tasks by tag.

leetcodemediumarrayhash-tablestringdesignsorting
LeetCode 2866 - Beautiful Towers II

The problem asks us to build a series of towers along a coordinate line, where each tower has a height constrained by a given maxHeights array.

leetcodemediumarraystackmonotonic-stack
LeetCode 2079 - Watering Plants

This problem asks us to simulate watering a row of plants with a watering can that has a fixed capacity. The plants are arranged along a straight line with indices representing their positions.

leetcodemediumarraysimulation
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 2749 - Minimum Operations to Make the Integer Zero

The problem gives us two integers, num1 and num2. In one operation, we may choose any integer i between 0 and 60, inclusive, and subtract the value 2^i + num2 from num1. The goal is to determine the minimum number of operations required to make num1 become exactly 0.

leetcodemediumbit-manipulationbrainteaserenumeration
CF 305D - Olya and Graph

We are given a directed acyclic graph with vertices numbered from 1 to n, where every edge goes from a smaller-numbered vertex to a larger-numbered vertex. Some edges already exist, and we are allowed to add more edges under certain constraints.

codeforcescompetitive-programmingcombinatoricsmath
LeetCode 3385 - Minimum Time to Break Locks II

In this problem, Bob must break a collection of locks, where each lock requires a certain minimum amount of energy before it can be destroyed. The input array strength represents these requirements.

leetcodehardarraybreadth-first-searchgraph-theory
LeetCode 2716 - Minimize String Length

The problem asks us to minimize the length of a given string s by repeatedly performing two types of deletion operations. In the first operation, we can pick a character at some index and delete the closest identical character to its left if one exists.

leetcodeeasyhash-tablestring
CF 155A - I_love_\%username\%

We are given the chronological contest scores of one programmer. A performance is called "amazing" when the current score is strictly greater than every previous score, or strictly smaller than every previous score.

codeforcescompetitive-programmingbrute-force
CF 153E - Euclidean Distance

We are given up to 50 points on a 2D plane. Each point has integer coordinates, and some points may coincide. The task is to find the largest Euclidean distance between any pair of points.

codeforcescompetitive-programming*special
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 3044 - Most Frequent Prime

The problem asks us to traverse a m x n integer matrix and generate numbers by moving in straight lines along eight possible directions: east, south-east, south, south-west, west, north-west, north, and north-east.

leetcodemediumarrayhash-tablemathmatrixcountingenumerationnumber-theory
LeetCode 2232 - Minimize Result by Adding Parentheses to Expression

The problem presents a string expression in the form "<num1+<num2", where both <num1 and <num2 are positive integers represented as strings.

leetcodemediumstringenumeration
LeetCode 2045 - Second Minimum Time to Reach Destination

Here is a comprehensive technical solution guide for LeetCode 2045 following your requested format: The problem asks us to find the second minimum time to travel from vertex 1 to vertex n in a weighted, undirected graph, where the weight of every edge is the same (time).

leetcodehardbreadth-first-searchgraph-theoryshortest-path
LeetCode 2383 - Minimum Hours of Training to Win a Competition

The problem gives us two starting values, initialEnergy and initialExperience, which represent the player's stats before entering a sequence of competitions. We are also given two arrays, energy and experience, where each index corresponds to an opponent.

leetcodeeasyarraygreedy
CF 256D - Liars and Serge

We have n people sitting at a table, each of whom is either always honest or always lies. Honest people always answer truthfully about how many honest people are at the table. Liars can pick any number from 1 to n except the true number.

codeforcescompetitive-programmingdp
LeetCode 2962 - Count Subarrays Where Max Element Appears at Least K Times

The problem asks us to count subarrays in an integer array nums where the maximum element of the subarray occurs at least k times.

leetcodemediumarraysliding-window
LeetCode 2583 - Kth Largest Sum in a Binary Tree

The problem gives us the root of a binary tree and an integer k. For every level in the tree, we calculate the sum of all node values that appear on that level. After computing all level sums, we must return the kth largest level sum.

leetcodemediumtreebreadth-first-searchsortingbinary-tree
LeetCode 2681 - Power of Heroes

The problem asks us to compute the total "power" across every possible non-empty subset of heroes. For any selected group of heroes, its power is defined as: We are given an array nums, where each value represents the strength of one hero.

leetcodehardarraymathdynamic-programmingsortingprefix-sum
LeetCode 2189 - Number of Ways to Build House of Cards

The problem is asking us to count the number of distinct ways to build a house of cards using exactly n cards. Each house consists of one or more rows of triangles formed by leaning two cards together, with horizontal cards placed between adjacent triangles.

leetcodemediummathdynamic-programming
LeetCode 3393 - Count Paths With the Given XOR Value

The problem gives us an m x n grid where each cell contains a small integer value. We start at the top left corner (0, 0) and must reach the bottom right corner (m - 1, n - 1) by moving only right or down. Along every path, we compute the XOR of all visited cell values.

leetcodemediumarraydynamic-programmingbit-manipulationmatrix
LeetCode 2702 - Minimum Operations to Make Numbers Non-positive

In this problem, we are given an array nums and two integers x and y, where x y. During each operation, we choose one index i and apply two different decrements: - nums[i] decreases by x - every other element decreases by y The goal is to determine the minimum number of…

leetcodehardarraybinary-search
LeetCode 3076 - Shortest Uncommon Substring in an Array

The problem asks us to find, for each string in a given array, the shortest substring that does not appear in any other string in the array. If multiple shortest substrings exist, we must choose the lexicographically smallest one.

leetcodemediumarrayhash-tablestringtrie
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 1955 - Count Number of Special Subsequences

This problem asks us to count the number of special subsequences in an array nums that consists only of integers 0, 1, and 2. A subsequence is special if it follows the pattern of one or more 0s, followed by one or more 1s, followed by one or more 2s.

leetcodehardarraydynamic-programming
LeetCode 2216 - Minimum Deletions to Make Array Beautiful

The problem asks us to transform a given integer array nums into a beautiful array using the minimum number of deletions. A beautiful array satisfies two conditions: its length is even, and no two consecutive elements at even indices are equal (nums[i] !

leetcodemediumarraystackgreedy
CF 435A - Queue on Bus Stop

We have a line of people waiting at a bus stop, but they are organized into groups. Each group has a fixed number of people and stands consecutively in the queue. A bus comes that can carry at most m people, and the people enter in the order of their groups.

codeforcescompetitive-programmingimplementation
LeetCode 3070 - Count Submatrices with Top-Left Element and Sum Less Than k

The problem gives us a 2D integer matrix called grid and an integer k. We need to count how many submatrices satisfy two conditions: 1. The submatrix must contain the top-left cell of the original matrix, which is grid[0][0]. 2.

leetcodemediumarraymatrixprefix-sum
CF 304B - Calendar

We are given two valid Gregorian calendar dates in the format yyyy:mm:dd. The task is to compute how many days lie between them.

codeforcescompetitive-programmingbrute-forceimplementation
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
LeetCode 2879 - Display the First Three Rows

The problem requires displaying the first three rows of a given DataFrame named employees. The DataFrame contains four columns: employeeid, name, department, and salary.

leetcodeeasy
LeetCode 3160 - Find the Number of Distinct Colors Among the Balls

The problem gives us limit + 1 balls labeled from 0 to limit. Initially, none of the balls have a color assigned. We then process a sequence of queries, where each query is of the form [x, y]. This means ball x should now be painted with color y.

leetcodemediumarrayhash-tablesimulation
CF 148B - Escape

We are asked to simulate a pursuit scenario between a princess and a dragon. The princess runs at a constant speed, and the dragon flies faster but only begins chasing after a delay. Each time the dragon catches up, the princess can drop a bijou to distract him.

codeforcescompetitive-programmingimplementationmath
LeetCode 3387 - Maximize Amount After Two Days of Conversions

This problem models currency conversions as graph traversal across two separate days. You begin with exactly 1.0 unit of initialCurrency, and you may perform any number of exchanges on day 1 using the first set of conversion rates, followed by any number of exchanges on day 2…

leetcodemediumarraystringdepth-first-searchbreadth-first-searchgraph-theory
CF 183E - Candy Shop

There are n kids sitting in a fixed cyclic order. During the buying process, the chosen package sizes must form a strictly increasing sequence globally across all turns. After kid n, the next turn goes back to kid 1.

codeforcescompetitive-programminggreedy
LeetCode 3166 - Calculate Parking Fees and Duration

This problem asks us to analyze parking transaction records and compute aggregated statistics for each car. Every row in the ParkingTransactions table represents one parking session, containing the parking lot ID, the car ID, the entry and exit timestamps, and the fee paid for…

leetcodemediumdatabase
CF 178A1 - Educational Game

We have an array of non-negative integers. In one move, we choose an index i with a[i] 0, decrease a[i] by one, and increase some position i + 2t by one. The destination index must have the same parity as i, because the distance moved is always even.

codeforcescompetitive-programming
CF 245D - Restoring Table

We are given a square table that was originally generated from a hidden array of non-negative integers. Each off-diagonal entry is the bitwise AND of the corresponding pair of hidden values, while diagonal entries are artificially replaced by -1.

codeforcescompetitive-programmingconstructive-algorithmsgreedy
LeetCode 1834 - Single-Threaded CPU

The problem asks us to simulate the execution of tasks on a single-threaded CPU. Each task has an enqueue time and a processing time.

leetcodemediumarraysortingheap-(priority-queue)
LeetCode 3063 - Linked List Frequency

This problem asks us to analyze a singly-linked list of integers and produce a new linked list containing the frequencies of each distinct element in the input list.

leetcodeeasyhash-tablelinked-listcounting
CF 139A - Petr and Book

Petr has a book with n pages. Starting from Monday, he reads a fixed number of pages each day of the week. The input gives those seven daily reading capacities in order from Monday to Sunday. We need to determine on which day Petr finishes the book.

codeforcescompetitive-programmingimplementation
LeetCode 2917 - Find the K-or of an Array

This problem introduces a generalized version of the bitwise OR operation called the K-or. In a normal bitwise OR, a bit in the result becomes 1 if at least one number has that bit set. The K-or operation changes this rule.

leetcodeeasyarraybit-manipulation
LeetCode 1893 - Check if All the Integers in a Range Are Covered

The problem asks us to determine whether every integer within a given inclusive range [left, right] is covered by at least one of the intervals specified in the ranges array.

leetcodeeasyarrayhash-tableprefix-sum
LeetCode 2699 - Modify Graph Edge Weights

You asked for a complete guide, but the previous message included two different LeetCode problems with full requirements: - LeetCode 2692 - Make Object Immutable - LeetCode 2699 - Modify Graph Edge Weights A full reference-quality guide for either one is quite large and should…

leetcodehardgraph-theoryheap-(priority-queue)shortest-path
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 2058 - Find the Minimum and Maximum Number of Nodes Between Critical Points

The problem gives us a singly linked list and asks us to identify all of its critical points. A critical point is a node that is either a local maximum or a local minimum.

leetcodemediumlinked-list
LeetCode 2212 - Maximum Points in an Archery Competition

The problem is asking us to determine the optimal way for Bob to distribute his numArrows across 12 scoring sections (from 0 to 11) in an archery competition in order to maximize his total points against Alice. Alice's arrow distribution is given in aliceArrows.

leetcodemediumarraybacktrackingbit-manipulationenumeration
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 2373 - Largest Local Values in a Matrix

The problem gives us an n x n square matrix called grid, where each cell contains an integer value. Our task is to construct a new matrix called maxLocal, whose dimensions are (n - 2) x (n - 2).

leetcodeeasyarraymatrix
LeetCode 2582 - Pass the Pillow

The problem describes a line of n people, numbered sequentially from 1 to n. Initially, person 1 holds a pillow. Every second, the pillow is passed to the adjacent person. The direction of passing changes whenever the pillow reaches either end of the line.

leetcodeeasymathsimulation
CF 432E - Square Tiling

We are asked to color an $n times m$ grid such that every contiguous region of the same color forms a square. Each square can be of any size, as long as it is a perfect square in shape and does not overlap another square of the same color.

codeforcescompetitive-programmingconstructive-algorithmsgreedy
LeetCode 2066 - Account Balance

This problem asks us to compute the running balance for every bank account after each transaction. We are given a table named Transactions where each row represents a single transaction performed by an account on a particular day.

leetcodemediumdatabase
LeetCode 2394 - Employees With Deductions

This problem asks us to identify employees whose monthly working time is less than the required number of hours. Each employee has a minimum number of hours they must work during October 2022 to avoid salary deductions.

leetcodemediumdatabase
LeetCode 2806 - Account Balance After Rounded Purchase

The problem is asking us to simulate a simple bank account deduction after making a purchase. You start with an initial balance of 100 dollars. The purchase amount is given as an integer, purchaseAmount, representing the cost of an item in dollars.

leetcodeeasymath
CF 202B - Brand New Easy Problem

We are given the title words of Lesha's new problem and several archive problems from Torcoder. The words in Lesha's title are all distinct. An archive title may repeat words.

codeforcescompetitive-programmingbrute-force
LeetCode 2763 - Sum of Imbalance Numbers of All Subarrays

For any array, its imbalance number is determined after sorting the elements. Suppose we have a subarray and sort it into sarr. We examine every adjacent pair in the sorted order.

leetcodehardarrayhash-tableenumeration
LeetCode 2326 - Spiral Matrix IV

The problem gives us a linked list and asks us to place its values into an m x n matrix in clockwise spiral order. We begin filling from the top-left corner of the matrix, which is position (0, 0). The traversal direction follows the standard spiral pattern: 1.

leetcodemediumarraylinked-listmatrixsimulation
LeetCode 1953 - Maximum Number of Weeks for Which You Can Work

The problem gives us an array called milestones, where each value represents how many milestones belong to a particular project. Every week, we must complete exactly one milestone from one project.

leetcodemediumarraygreedy
LeetCode 2734 - Lexicographically Smallest String After Substring Operation

The problem gives us a lowercase English string s. We must perform exactly one operation: 1. Choose any non-empty substring. 2. Replace every character in that substring with the previous character in the alphabet.

leetcodemediumstringgreedy
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 236B - Easy Number Challenge

We need to compute the sum of the number of divisors of every product i j k, where i ranges from 1 to a, j ranges from 1 to b, and k ranges from 1 to c. For each triple (i, j, k), we evaluate d(i j k), where d(x) means the number of positive divisors of x.

codeforcescompetitive-programmingimplementationnumber-theory
LeetCode 2157 - Groups of Strings

The problem asks us to group a list of unique lowercase strings based on a special notion of connectivity. Each string can be represented as a set of letters, and two strings are connected if one can be transformed into the other with exactly one operation: adding a letter…

leetcodehardarrayhash-tablestringbit-manipulationunion-find
CF 413A - Data Recovery

The problem gives us a sequence of processor temperatures recorded over n steps. The chief engineer has reliable notes of the minimum and maximum temperature observed, but the assistant only recorded m of the n temperatures.

codeforcescompetitive-programmingimplementation
LeetCode 1991 - Find the Middle Index in Array

The problem gives us a 0-indexed integer array called nums. We need to find an index such that the sum of all elements to the left of that index is equal to the sum of all elements to the right of that index. More formally, for an index i: - Left sum = nums[0] + nums[1] + ...

leetcodeeasyarrayprefix-sum
LeetCode 3189 - Minimum Moves to Get a Peaceful Board

In this problem, we are given the positions of n rooks placed on an n x n chessboard. Each rook is represented as a pair [xi, yi], where xi is the row index and yi is the column index.

leetcodemediumarraygreedysortingcounting-sort
LeetCode 2401 - Longest Nice Subarray

The problem gives an array of positive integers and asks for the length of the longest contiguous subarray that is considered "nice". A subarray is nice when every pair of distinct elements inside it has a bitwise AND equal to 0.

leetcodemediumarraybit-manipulationsliding-window
LeetCode 2959 - Number of Possible Sets of Closing Branches

This problem asks us to determine the number of possible sets of branches that can be closed such that the maximum distance between any pair of remaining open branches does not exceed a given maxDistance.

leetcodehardbit-manipulationgraph-theoryheap-(priority-queue)enumerationshortest-path
CF 249D - Donkey and Stars

We are asked to find the longest chain of stars the Donkey can select under a geometric rule. The stars are points on a plane, and we begin at the origin. From any star, we imagine two rays at fixed angles relative to the horizontal axis.

codeforcescompetitive-programmingdata-structuresdpgeometrymathsortings
LeetCode 2392 - Build a Matrix With Conditions

This guide is long enough that a complete, high quality response will exceed a practical single-message length if I include all requested sections in full detail, including detailed worked examples, Python and Go implementations, test coverage, and edge case analysis.

leetcodehardarraygraph-theorytopological-sortmatrix