brain

tamnd's digital brain — notes, problems, research

43815 notes

LeetCode 1169 - Invalid Transactions

The problem asks us to identify transactions that are potentially invalid based on two rules. First, any transaction with an amount greater than $1000 is invalid.

leetcodemediumarrayhash-tablestringsorting
LeetCode 1012 - Numbers With Repeated Digits

The problem asks us to count how many integers in the range [1, n] contain at least one repeated digit. A repeated digit means that some digit appears more than once in the number. For example, 11 has a repeated 1, 100 has repeated 0, and 121 has repeated 1.

leetcodehardmathdynamic-programming
CF 32D - Constellation

We are given a 2D grid of size _n_ by _m_, each cell either containing a star * or empty .. The task is to locate constellations shaped like a cross.

codeforcescompetitive-programmingimplementation
LeetCode 692 - Top K Frequent Words

The problem gives us an array of strings called words and an integer k. Each string represents a word, and words may appear multiple times in the array. Our task is to return the k most frequent words. The result must follow two ordering rules.

leetcodemediumarrayhash-tablestringtriesortingheap-(priority-queue)bucket-sortcounting
LeetCode 23 - Merge k Sorted Lists

The problem gives us an array of k sorted linked lists. Each linked list is already sorted in ascending order, and our task is to combine all of them into one single sorted linked list. A linked list node contains a value and a pointer to the next node.

leetcodehardlinked-listdivide-and-conquerheap-(priority-queue)merge-sort
LeetCode 1815 - Maximum Number of Groups Getting Fresh Donuts

This problem asks us to maximize the number of “happy” customer groups by choosing the best possible ordering of the groups. The donut shop produces donuts in batches of exactly batchSize. A fresh batch starts only when the previous batch has been completely consumed.

leetcodehardarraydynamic-programmingbit-manipulationmemoizationbitmask
LeetCode 395 - Longest Substring with At Least K Repeating Characters

The problem asks us to find the length of the longest substring in which every character appears at least k times. A substring is a contiguous sequence of characters inside the original string.

leetcodemediumhash-tablestringdivide-and-conquersliding-window
LeetCode 1540 - Can Convert String in K Moves

The problem is asking whether it is possible to convert one string s into another string t using at most k moves, follow

leetcodemediumhash-tablestring
CF 103E - Buying Sets

We are given several sets of integers, each with an associated cost. We may choose any collection of these sets, including the empty collection. Let the number of chosen sets be $k$, and let the union of all chosen sets contain $u$ distinct integers.

codeforcescompetitive-programmingflowsgraph-matchings
CF 59C - Title

We are given a string template consisting of lowercase letters and question marks. The final string must satisfy three conditions simultaneously. First, it must be a palindrome, so characters mirrored around the center must match.

codeforcescompetitive-programmingexpression-parsing
LeetCode 923 - 3Sum With Multiplicity

The problem asks us to count how many index triplets (i, j, k) satisfy two conditions: - The indices must follow the order i < j < k - The values at those indices must sum to the given target Formally, we want: The important detail is that we are counting tuples of indices…

leetcodemediumarrayhash-tabletwo-pointerssortingcounting
LeetCode 1433 - Check If a String Can Break Another String

The problem asks us to determine whether one string can "break" another string through some permutation. Given two strin

leetcodemediumstringgreedysorting
LeetCode 1750 - Minimum Length of String After Deleting Similar Ends

The problem gives us a string s containing only the characters 'a', 'b', and 'c'. We may repeatedly perform a deletion operation on the string.

leetcodemediumtwo-pointersstring
CF 69C - Game

Each player owns a multiset of artifacts. Some artifacts are basic and can be purchased directly. Some are composite and can be crafted from several basic artifacts in fixed quantities. Whenever a player buys a basic artifact, it is added to their inventory.

codeforcescompetitive-programmingimplementation
CF 65A - Harry Potter and Three Spells

We have three transformation spells that convert one material into another. The first spell turns a grams of sand into b grams of lead. The second spell turns c grams of lead into d grams of gold. The third spell turns e grams of gold into f grams of sand.

codeforcescompetitive-programmingimplementationmath
LeetCode 77 - Combinations

This problem asks us to generate all possible combinations of size k from the numbers in the inclusive range [1, n].

leetcodemediumbacktracking
LeetCode 1481 - Least Number of Unique Integers after K Removals

This problem asks us to minimize the number of unique integers in an array after removing exactly k elements. In other words, we are given a list arr and a number k, and we need to strategically remove k elements so that the count of distinct integers left in the array is as…

leetcodemediumarrayhash-tablegreedysortingcounting
CF 18D - Seller Bob

Bob experiences one event per day. A day is either a prize day or a customer day.

codeforcescompetitive-programmingbrute-forcedpgreedy
LeetCode 1119 - Remove Vowels from a String

The problem asks us to remove vowels from a given string s. Specifically, the vowels are defined as the lowercase characters 'a', 'e', 'i', 'o', and 'u'. The input string consists only of lowercase English letters, and its length ranges from 1 to 1000.

leetcodeeasystring
LeetCode 798 - Smallest Rotation with Highest Score

The problem asks us to determine the optimal rotation of an array nums so that the resulting array achieves the highest possible score, where a score is defined as the number of elements that are less than or equal to their index after rotation.

leetcodehardarrayprefix-sum
CF 15A - Cottage Village

We are given a one-dimensional map of a village where all the houses lie along the _x_-axis. Each house is square, specified by its center coordinate and its side length. No two houses overlap, though they may touch edges.

codeforcescompetitive-programmingimplementationsortings
LeetCode 856 - Score of Parentheses

The problem is asking us to compute a score for a string of balanced parentheses according to a set of rules. A balanced parentheses string is one in which every opening parenthesis '(' has a corresponding closing parenthesis ')' and the pairs are properly nested.

leetcodemediumstringstack
LeetCode 682 - Baseball Game

This problem asks us to simulate a baseball scoring system with a set of unusual rules. We begin with an empty score record and process a sequence of operations one by one. Each operation either adds a new score or modifies the history of previously recorded scores.

leetcodeeasyarraystacksimulation
LeetCode 1087 - Brace Expansion

In this problem, we are given a string that represents multiple possible words. Each position in the word may contain either a single fixed character or a set of alternative characters enclosed in curly braces.

leetcodemediumstringbacktrackingstackbreadth-first-searchsorting
LeetCode 680 - Valid Palindrome II

The problem asks whether a given string s can become a palindrome after deleting at most one character. A palindrome is a string that reads the same forwards and backwards.

leetcodeeasytwo-pointersstringgreedy
LeetCode 277 - Find the Celebrity

This problem asks us to identify whether there is a "celebrity" among n people at a party. A celebrity has a very specific property: - Every other person knows the celebrity. - The celebrity knows nobody else. We are not given the entire relationship graph directly.

leetcodemediumtwo-pointersgraph-theoryinteractive
LeetCode 1507 - Reformat Date

The problem gives a date string in a human readable format such as "20th Oct 2052" and asks us to convert it into the st

leetcodeeasystring
LeetCode 1358 - Number of Substrings Containing All Three Characters

The problem asks us to count all substrings of a given string s that contain at least one occurrence of each character '

leetcodemediumhash-tablestringsliding-window
LeetCode 14 - Longest Common Prefix

The problem gives an array of strings and asks us to find the longest prefix shared by every string in the array. A prefix is a sequence of characters that appears at the beginning of a string.

leetcodeeasyarraystringtrie
CF 38H - The Great Marathon

We have a connected weighted graph of cities. Runner i starts from city i and finishes in some other city. The finish city is chosen independently for every runner, and several runners may share the same destination.

codeforcescompetitive-programmingdp
LeetCode 887 - Super Egg Drop

The problem asks us to determine the minimum number of moves required to identify a critical floor in a building using a limited number of eggs.

leetcodehardmathbinary-searchdynamic-programming
CF 16B - Burglar and Matches

We have a burglar who can carry exactly n matchboxes. In the warehouse, there are m containers. Each container i has a_i matchboxes, and every matchbox in that container contains b_i matches.

codeforcescompetitive-programminggreedyimplementationsortings
CF 95E - Lucky Country

We are given a set of islands connected by bidirectional roads. The islands form regions: each region is a connected component, and islands in different regions have no path between them.

codeforcescompetitive-programmingdpdsugraphs
LeetCode 435 - Non-overlapping Intervals

The problem gives an array of intervals where each interval is represented as [start, end]. Each interval describes a continuous range on a number line. The task is to remove the minimum number of intervals so that the remaining intervals no longer overlap.

leetcodemediumarraydynamic-programminggreedysorting
LeetCode 383 - Ransom Note

This problem asks whether it is possible to construct the string ransomNote using characters taken from the string magazine. Each character in magazine can only be used once, which means character frequency matters.

leetcodeeasyhash-tablestringcounting
LeetCode 1212 - Team Scores in Football Tournament

This problem asks us to compute the total points for each football team after a series of matches in a tournament. The scoring rules are standard: a win gives 3 points, a draw gives 1 point, and a loss gives 0 points. The input consists of two tables: Teams and Matches.

leetcodemediumdatabase
CF 61A - Ultra-Fast Mathematician

We are given two binary strings of equal length. Each character is either '0' or '1'. For every position, we compare the characters from the two strings. If the two characters are different, the resulting string gets '1' at that position.

codeforcescompetitive-programmingimplementation
CF 38C - Blinds

We have a set of horizontal blind stripes of varying lengths, and our goal is to construct a rectangular blind for a window using these stripes. Each stripe can be cut into smaller pieces, but pieces cannot be shorter than a given minimum length, l.

codeforcescompetitive-programmingbrute-force
LeetCode 1154 - Day of the Year

The problem asks us to compute the ordinal day number of a year given a date in the format YYYY-MM-DD. For example, January 1st is always day 1, January 2nd is day 2, and December 31st is either day 365 or 366 depending on whether the year is a leap year.

leetcodeeasymathstring
LeetCode 977 - Squares of a Sorted Array

The problem asks us to take an array of integers nums that is already sorted in non-decreasing order and return a new array containing the squares of each number, also sorted in non-decreasing order.

leetcodeeasyarraytwo-pointerssorting
LeetCode 1028 - Recover a Tree From Preorder Traversal

The problem provides a string traversal representing a preorder depth-first traversal of a binary tree, where each node is represented by its value preceded by D dashes, with D being the depth of the node in the tree. The root node has depth 0 and is not preceded by any dash.

leetcodehardstringtreedepth-first-searchbinary-tree
LeetCode 1438 - Longest Continuous Subarray With Absolute Diff Less Than or Equal to Limit

The problem asks us to find the length of the longest contiguous subarray in an integer array nums such that the absolut

leetcodemediumarrayqueuesliding-windowheap-(priority-queue)ordered-setmonotonic-queue
LeetCode 1326 - Minimum Number of Taps to Open to Water a Garden

The problem describes a one-dimensional garden that stretches from position 0 to position n. At every integer position i, there is a tap that may water some interval around it.

leetcodehardarraydynamic-programminggreedy
CF 73E - Morrowindows

Each viewing mode groups the inventory into pages of size ai. If the inventory contains k items, then the game shows $bi = leftlceil frac{k}{ai} rightrceil$ pages in that mode. Vasya does not know the actual value of k, only that 2 ≤ k ≤ x.

codeforcescompetitive-programmingmathnumber-theory
LeetCode 1556 - Thousand Separator

The problem asks us to format a non-negative integer so that every group of three digits is separated by a dot (.), starting from the right side of the number. For example, the number 1234567 should become "1.234.

leetcodeeasystring
LeetCode 1312 - Minimum Insertion Steps to Make a String Palindrome

Edit The problem gives us a string s and asks for the minimum number of insertion operations required to transform the s

leetcodehardstringdynamic-programming
LeetCode 1543 - Fix Product Name Format

The problem asks us to clean and aggregate sales data from a Sales table. Each row contains a unique saleid, a productna

leetcodeeasydatabase
LeetCode 1079 - Letter Tile Possibilities

The problem asks us to count all possible non-empty sequences that can be formed from a set of letter tiles, where each tile has a single uppercase letter. The input is a string tiles representing the letters available on the tiles.

leetcodemediumhash-tablestringbacktrackingcounting
LeetCode 530 - Minimum Absolute Difference in BST

This problem gives us the root node of a Binary Search Tree, abbreviated as BST, and asks us to find the minimum absolute difference between the values of any two distinct nodes in the tree.

leetcodeeasytreedepth-first-searchbreadth-first-searchbinary-search-treebinary-tree
LeetCode 2981 - Find Longest Special Substring That Occurs Thrice I

The problem asks us to find the longest special substring that appears at least three times in the given string s. A sub

leetcodemediumhash-tablestringbinary-searchsliding-windowcounting
LeetCode 597 - Friend Requests I: Overall Acceptance Rate

This problem asks us to compute the overall acceptance rate of friend requests in a social network system. Two database tables are provided. The first table, FriendRequest, stores all friend requests that users sent to each other.

leetcodeeasydatabase
LeetCode 1560 - Most Visited Sector in a Circular Track

In this problem, we are given a circular track divided into n sectors, numbered from 1 to n. A marathon runner moves around this track in increasing numerical order, and after sector n, the runner wraps back to sector 1.

leetcodeeasyarraysimulation
LeetCode 745 - Prefix and Suffix Search

The problem asks us to design a data structure that supports efficient searches based on both a prefix and a suffix. We are given an array of words, where each word has an implicit index based on its position in the array. The WordFilter class must support two operations: 1.

leetcodehardarrayhash-tablestringdesigntrie
LeetCode 167 - Two Sum II - Input Array Is Sorted

This problem gives us a sorted, 1-indexed array of integers called numbers and a target integer target. Our task is to find exactly two numbers in the array whose sum equals target, then return their 1-based indices.

leetcodemediumarraytwo-pointersbinary-search
LeetCode 1404 - Number of Steps to Reduce a Number in Binary Representation to One

The problem gives us a binary number represented as a string s. Our task is to determine how many operations are require

leetcodemediumstringbit-manipulationsimulation
CF 101E - Candies and Stones

Gerald repeatedly removes either one candy or one stone. After every move, Mike looks at how many candies and stones Gerald has already eaten. If Gerald has eaten a candies and b stones so far, Mike awards $$f(a,b) = (xa + yb) bmod p$$ points.

codeforcescompetitive-programmingdivide-and-conquerdp
LeetCode 1369 - Get the Second Most Recent Activity

The problem gives us a database table named UserActivity that stores activity periods for different users. Each row cont

leetcodeharddatabase
LeetCode 689 - Maximum Sum of 3 Non-Overlapping Subarrays

The problem asks us to select exactly three non-overlapping subarrays from the input array nums, where each subarray has length k. Among all valid choices, we must maximize the total sum of all elements contained in those three subarrays.

leetcodehardarraydynamic-programmingsliding-windowprefix-sum
LeetCode 985 - Sum of Even Numbers After Queries

The problem gives us an integer array nums and a list of update operations called queries. Each query contains two values: - vali, the amount to add - indexi, the position in the array to update For every query, we must first update the array element: After applying the update…

leetcodemediumarraysimulation
CF 124A - The number of positions

Petr is standing somewhere in a line containing n people. Positions are numbered from 1 at the front to n at the back. He knows two things about his position. At least a people are standing in front of him, and at most b people are standing behind him.

codeforcescompetitive-programmingmath
CF 45A - Codecraft III

We are given the current month as a string and an integer k representing how many months later a new game release will happen. The task is to determine the month after advancing exactly k months forward in the calendar.

codeforcescompetitive-programmingimplementation
LeetCode 825 - Friends Of Appropriate Ages

The problem gives us an array ages, where each value represents the age of a person on a social media platform. We must determine how many friend requests are sent between people according to a specific set of rules.

leetcodemediumarraytwo-pointersbinary-searchsorting
LeetCode 1228 - Missing Number In Arithmetic Progression

The problem asks us to find a missing value from an array that originally formed an arithmetic progression (AP). An arithmetic progression is a sequence where the difference between consecutive terms is constant, i.e., arr[i + 1] - arr[i] is the same for every consecutive pair.

leetcodeeasyarraymath
LeetCode 669 - Trim a Binary Search Tree

LeetCode 669, Trim a Binary Search Tree, asks us to modify a binary search tree so that every remaining node has a value within the inclusive range [low, high].

leetcodemediumtreedepth-first-searchbinary-search-treebinary-tree
CF 74C - Chessboard Billiard

We have an n × m chessboard. A billiard ball moves diagonally like a bishop, but unlike a bishop it reflects off the borders of the board. When it hits a vertical wall, the horizontal component of the direction flips. When it hits a horizontal wall, the vertical component flips.

codeforcescompetitive-programmingdfs-and-similardsugraphsnumber-theory
LeetCode 1695 - Maximum Erasure Value

This problem asks us to find a contiguous subarray that contains only unique elements, meaning no value appears more than once inside that subarray. Among all such valid subarrays, we must return the maximum possible sum of its elements.

leetcodemediumarrayhash-tablesliding-window
CF 57E - Chess

We start on an infinite chessboard at square (0, 0). A knight moves using the usual chess move, two cells in one direction and one in the perpendicular direction. Some squares are removed from the board, and the knight is never allowed to stand on them.

codeforcescompetitive-programmingmathshortest-paths
LeetCode 97 - Interleaving String

This problem asks us to determine whether a string s3 can be formed by interleaving two other strings, s1 and s2. An interleaving means we combine characters from s1 and s2 while preserving the relative order of characters within each original string.

leetcodemediumstringdynamic-programming
CF 15D - Map

We are given a rectangular map of size n × m, where each cell has a non-negative height. Peter wants to build cities of size a × b. To place a city, he must level the ground inside its rectangle by reducing all cells to the minimum height within that rectangle.

codeforcescompetitive-programmingdata-structuresimplementationsortings
LeetCode 329 - Longest Increasing Path in a Matrix

The problem gives us a two-dimensional grid of integers called matrix. Each position in the grid contains a value, and we are asked to find the length of the longest strictly increasing path.

leetcodehardarraydynamic-programmingdepth-first-searchbreadth-first-searchgraph-theorytopological-sortmemoizationmatrix
LeetCode 806 - Number of Lines To Write String

This problem is asking us to determine how to write a string s on multiple lines when each character has a specific pixel width and no line can exceed 100 pixels.

leetcodeeasyarraystring
CF 10B - Cinema Cashier

The problem describes a cinema hall in Berland with K rows and K seats per row, where K is always odd. Customers come in groups of size M and request consecutive seats.

codeforcescompetitive-programmingdpimplementation
LeetCode 1281 - Subtract the Product and Sum of Digits of an Integer

The problem asks us to compute a simple mathematical transformation on the digits of an integer. Given an integer n, we

leetcodeeasymath
CF 118E - Bertown roads

We are given a connected undirected graph representing the road network of Bertown, where junctions are nodes and roads are edges.

codeforcescompetitive-programmingdfs-and-similargraphs
CF 45G - Prime Problem

We have houses numbered from 1 to n. Every house must receive a color. For each color, if we add together all house indices painted with that color, the result must be a prime number.

codeforcescompetitive-programmingnumber-theory
CF 27A - Next Test

We are given the indices of tests that already exist in the system. Every index is a positive integer, and all indices are distinct. The task is to find the smallest positive integer that does not appear in the list.

codeforcescompetitive-programmingimplementationsortings
LeetCode 505 - The Maze II

This problem presents a maze represented as a 2D grid of size m x n where each cell is either an empty space (0) or a wall (1). A ball starts at a given position and can roll up, down, left, or right.

leetcodemediumarraydepth-first-searchbreadth-first-searchgraph-theoryheap-(priority-queue)matrixshortest-path
LeetCode 1270 - All People Report to the Given Manager

The problem asks us to identify all employees in a company who directly or indirectly report to the head of the company,

leetcodemediumdatabase
LeetCode 621 - Task Scheduler

The Task Scheduler problem asks us to determine the minimum number of CPU intervals required to complete a list of tasks with a cooling constraint. Each task is represented by an uppercase letter A-Z. The CPU can execute one task per interval or remain idle.

leetcodemediumarrayhash-tablegreedysortingheap-(priority-queue)counting
CF 46G - Emperor's Problem

We are asked to construct a convex polygon with vertices that satisfies three conditions. First, all vertices must lie on lattice points, meaning each coordinate is an integer. Second, all sides must have distinct lengths.

codeforcescompetitive-programminggeometry
LeetCode 3028 - Ant on the Boundary

The problem describes an ant moving along a one-dimensional infinite line, starting at a boundary point, which we can co

leetcodeeasyarraysimulationprefix-sum
LeetCode 978 - Longest Turbulent Subarray

The problem asks us to find the length of the longest turbulent subarray inside a given integer array arr. A subarray is considered turbulent if the relationship between every adjacent pair of numbers alternates between greater than () and less than (<).

leetcodemediumarraydynamic-programmingsliding-window
LeetCode 976 - Largest Perimeter Triangle

The problem gives us an array of integers called nums, where each integer represents a possible side length. Our goal is to select exactly three lengths that can form a valid triangle with a non-zero area, and among all valid triangles, return the maximum possible perimeter.

leetcodeeasyarraymathgreedysorting
LeetCode 1064 - Fixed Point

The problem is asking us to find a "fixed point" in a sorted array of distinct integers. A fixed point is an index i such that the value at that index equals the index itself, i.e., arr[i] == i.

leetcodeeasyarraybinary-search
LeetCode 604 - Design Compressed String Iterator

This problem asks us to implement a compressed string iterator. We are given a string where each character is immediately followed by a number representing how many times that character appears consecutively in the uncompressed version. For example, "a3b2" represents "aaabb".

leetcodeeasyarraystringdesigniterator
LeetCode 1841 - League Statistics

This problem asks us to compute a complete league table from two database tables, Teams and Matches. The Teams table contains the identity of each team in the league. Each row represents one team and includes a unique teamid and the corresponding teamname.

leetcodemediumdatabase
CF 75E - Ship's Shortest Path

We are given two points in the plane, the ship's starting position and destination, together with a convex polygon representing an island. Moving through the sea costs 1 per unit distance. Moving through the interior of the island costs 2 per unit distance.

codeforcescompetitive-programminggeometryshortest-paths
LeetCode 664 - Strange Printer

The problem describes a "strange printer" that can print sequences of the same character in one turn. The printer can overwrite any existing characters in the string.

leetcodehardstringdynamic-programming
CF 15B - Laser

We have a rectangular grid with n columns and m rows. Two lasers point at two different cells. Both lasers always move together, meaning their relative offset never changes. If one laser moves by (dx, dy), the other must move by exactly the same vector.

codeforcescompetitive-programmingmath
LeetCode 423 - Reconstruct Original Digits from English

The problem asks us to reconstruct digits from a jumbled string of English letters representing numbers from 0 to 9.

leetcodemediumhash-tablemathstring
LeetCode 1778 - Shortest Path in a Hidden Grid

This problem asks us to find the shortest path from a robot's unknown starting position to a hidden target inside a grid. The major challenge is that the grid itself is not directly accessible.

leetcodemediumarraydepth-first-searchbreadth-first-searchmatrixinteractive
LeetCode 1666 - Change the Root of a Binary Tree

This problem asks us to reroot a binary tree at a given leaf node. Normally, a binary tree has a single root, and every node points downward to its children. In this problem, each node also contains a parent pointer, which allows traversal upward toward the root.

leetcodemediumtreedepth-first-searchbinary-tree
CF 15E - Triangles

The picture in the statement describes a recursive triangular arrangement of paths and blocked regions. The black segments form a planar graph, and the gray triangles represent forbidden forest areas.

codeforcescompetitive-programmingcombinatoricsdp
LeetCode 930 - Binary Subarrays With Sum

The problem asks us to count the number of contiguous subarrays in a binary array nums whose sum equals a given integer goal. A binary array only contains 0s and 1s.

leetcodemediumarrayhash-tablesliding-windowprefix-sum
LeetCode 2067 - Number of Equal Count Substrings

The problem asks us to count the number of substrings in a string s such that every unique character in the substring occurs exactly count times. A substring is a contiguous segment of the string, so we are only considering consecutive characters.

leetcodemediumhash-tablestringsliding-windowcounting
LeetCode 1486 - XOR Operation in an Array

The problem gives us two integers, n and start. We must construct an array named nums of length n, where each element is

leetcodeeasymathbit-manipulation
LeetCode 694 - Number of Distinct Islands

The problem gives us a binary matrix called grid, where each cell contains either 0 or 1. A value of 1 represents land, and a value of 0 represents water. An island is formed by connecting adjacent land cells in the four cardinal directions: up, down, left, and right.

leetcodemediumarrayhash-tabledepth-first-searchbreadth-first-searchunion-findsortingmatrixhash-function
LeetCode 1203 - Sort Items by Groups Respecting Dependencies

This problem asks us to sort n items while satisfying two different kinds of constraints at the same time. The first constraint comes from dependencies between items. If item a appears in beforeItems[b], then item a must appear before item b in the final ordering.

leetcodeharddepth-first-searchbreadth-first-searchgraph-theorytopological-sort
CF 111B - Petya and Divisors

We are asked to process a sequence of queries, each defined by two integers, x and y. For each query, we need to count how many positive divisors of x do not divide any of the y numbers immediately preceding x in the sequence, that is, the numbers x-y, x-y+1, ..., x-1.

codeforcescompetitive-programmingbinary-searchdata-structuresnumber-theory
CF 132E - Bits of merry old England

The task is to print a given sequence of integers using a limited number of variables and two operations: assigning a variable to an integer, and printing a variable. Each assignment carries a cost equal to the number of set bits in the assigned number, while printing is free.

codeforcescompetitive-programmingflowsgraphs