brain

tamnd's digital brain — notes, problems, research

43815 notes

CF 328B - Sheldon and Ice Pieces

Here’s a automatically by

codeforcescompetitive-programminggreedy
LeetCode 2841 - Maximum Sum of Almost Unique Subarray

The problem gives us an integer array nums and two integers, m and k. We must examine every contiguous subarray whose length is exactly k. Among those subarrays, we only consider the ones that contain at least m distinct values. These are called almost unique subarrays.

leetcodemediumarrayhash-tablesliding-window
LeetCode 3208 - Alternating Groups II

The problem gives us a circular array called colors, where each value represents a tile color. A value of 0 means red, and a value of 1 means blue. We are also given an integer k. We must count how many groups of exactly k contiguous tiles form an alternating sequence.

leetcodemediumarraysliding-window
LeetCode 2337 - Move Pieces to Obtain a String

The problem gives us two strings, start and target, both having the same length. Each position in the strings contains one of three characters: - 'L', representing a piece that can only move left - 'R', representing a piece that can only move right - '', representing an empty…

leetcodemediumtwo-pointersstring
LeetCode 3389 - Minimum Operations to Make Character Frequencies Equal

The problem requires transforming a given string s into a good string, where a good string is defined as one in which every character appears the same number of times.

leetcodehardhash-tablestringdynamic-programmingcountingenumeration
LeetCode 3059 - Find All Unique Email Domains

This problem asks us to analyze email addresses stored in a database table and determine how many people belong to each unique email domain, but only for domains ending in .com.

leetcodeeasydatabase
LeetCode 2006 - Count Number of Pairs With Absolute Difference K

The problem gives us an integer array nums and an integer k. We need to count how many pairs of indices (i, j) satisfy two conditions: 1. i < j 2.

leetcodeeasyarrayhash-tablecounting
LeetCode 2433 - Find The Original Array of Prefix Xor

The problem is asking us to reverse-engineer an array arr from its prefix XOR array pref. Specifically, pref[i] represents the XOR of all elements in arr from index 0 to i. Our goal is to reconstruct arr given only pref.

leetcodemediumarraybit-manipulation
LeetCode 2269 - Find the K-Beauty of a Number

The problem asks us to calculate the k-beauty of a given integer num. To do this, we treat num as a string and examine every possible contiguous substring of length k. For each substring, we interpret it as an integer and check whether it divides the original number num evenly.

leetcodeeasymathstringsliding-window
CF 325A - Square and Rectangles

We are given up to five axis-aligned rectangles on a plane. Each rectangle is defined by its bottom-left and top-right coordinates. No two rectangles overlap, although they may touch at edges or corners.

codeforcescompetitive-programmingimplementation
LeetCode 2474 - Customers With Strictly Increasing Purchases

The problem gives us an Orders table where each row represents a purchase made by a customer. Every order has an orderid, a customerid, an orderdate, and a price.

leetcodeharddatabase
LeetCode 2736 - Maximum Sum Queries

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

leetcodehardarraybinary-searchstackbinary-indexed-treesegment-treesortingmonotonic-stack
LeetCode 3027 - Find the Number of Ways to Place People II

The problem asks us to determine how many valid placements of Alice and Bob exist on a 2D grid of points such that Alice can build a rectangular fence with her position as the upper left corner and Bob’s position as the lower right corner.

leetcodehardarraymathgeometrysortingenumeration
LeetCode 2041 - Accepted Candidates From the Interviews

The problem gives us two database tables, Candidates and Rounds, that together describe interview performance for job candidates. The Candidates table contains one row per candidate.

leetcodemediumdatabase
CF 439D - Devu and his Brother

We are given two integer arrays, one belonging to Devu and the other to his brother. We are allowed to repeatedly increase or decrease any single element of either array by 1 in one operation.

codeforcescompetitive-programmingbinary-searchsortingsternary-searchtwo-pointers
LeetCode 2246 - Longest Path With Different Adjacent Characters

The problem gives a tree with n nodes labeled 0 to n-1, rooted at node 0. The tree is represented using a parent array, where parent[i] indicates the parent of node i. Node 0 has no parent, so parent[0] == -1.

leetcodehardarraystringtreedepth-first-searchgraph-theorytopological-sort
CF 250C - Movie Critics

We are given a sequence of movie genres scheduled over n days, with exactly one movie per day. There are k genres, and each genre appears at least once. Valentine, a critic, experiences stress whenever the genre of consecutive movies he watches changes.

codeforcescompetitive-programminggreedy
LeetCode 3121 - Count the Number of Special Characters II

The problem gives us a string word containing uppercase and lowercase English letters. We must count how many letters are considered "special". A character c is special if two conditions are true: 1. The lowercase version of the letter appears somewhere in the string. 2.

leetcodemediumhash-tablestring
LeetCode 2693 - Call Function with Custom Context

This problem asks us to implement a custom version of JavaScript’s Function.prototype.call method, called callPolyfill. The purpose is to execute a function with an explicit this context. Normally, in JavaScript, this depends on how a function is called.

leetcodemedium
LeetCode 3153 - Sum of Digit Differences of All Pairs

The problem asks us to compute the total digit difference across every pair of numbers in the array. All numbers have the same number of digits. For any two numbers, their digit difference is defined as the number of positions where the digits are different.

leetcodemediumarrayhash-tablemathcounting
LeetCode 3304 - Find the K-th Character in String Game I

The problem defines an infinite string-building process that starts with the string "a". At every operation, we take the current string and create a transformed version where every character is replaced by the next character in the alphabet.

leetcodeeasymathbit-manipulationrecursionsimulation
LeetCode 2122 - Recover the Original Array

The problem presents a scenario in which Alice has an original array arr of length n consisting of positive integers. She chooses a positive integer k and generates two new arrays: lower and higher.

leetcodehardarrayhash-tabletwo-pointerssortingenumeration
LeetCode 1877 - Minimize Maximum Pair Sum in Array

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

leetcodemediumarraytwo-pointersgreedysorting
LeetCode 3311 - Construct 2D Grid Matching Graph Layout

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

leetcodehardarrayhash-tablegraph-theorymatrix
LeetCode 2832 - Maximal Range That Each Element Is Maximum in It

We are given an array nums consisting of distinct integers. For every position i, we need to determine the maximum possible length of a contiguous subarray in which nums[i] is the largest element. More formally, for each index i, we want to find the longest subarray nums[l..

leetcodemediumarraystackmonotonic-stack
LeetCode 2496 - Maximum Value of a String in an Array

This problem asks us to compute the maximum value of strings in an array according to a specific definition of value. Each string can either be entirely numeric or alphanumeric. If a string consists only of digits, its value is the integer it represents.

leetcodeeasyarraystring
LeetCode 2276 - Count Integers in Intervals

This problem asks us to design a data structure that dynamically maintains a collection of integer intervals and efficiently reports how many distinct integers are covered by at least one interval. Initially, the interval set is empty.

leetcodeharddesignsegment-treeordered-set
LeetCode 2724 - Sort By

This problem asks us to sort an array using a custom sorting rule. Instead of sorting elements directly by their own value, we are given a function fn that transforms each element into a numeric value, and that numeric value determines the order.

leetcodeeasy
LeetCode 2924 - Find Champion II

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

leetcodemediumgraph-theory
LeetCode 3268 - Find Overlapping Shifts II

The problem asks us to analyze shift overlaps for employees. We are given a table EmployeeShifts with columns employeeid, starttime, and endtime. Each row represents one work shift for an employee.

leetcodeharddatabase
LeetCode 3233 - Find the Count of Numbers Which Are Not Special

The problem asks us to count how many integers in the inclusive range [l, r] are not special. A number is considered special if it has exactly two proper divisors. A proper divisor of a number x is any positive divisor of x other than x itself.

leetcodemediumarraymathnumber-theory
LeetCode 2972 - Count the Number of Incremovable Subarrays II

The problem gives us an array nums of positive integers and asks us to count how many contiguous non-empty subarrays can be removed so that the remaining elements form a strictly increasing array.

leetcodehardarraytwo-pointersbinary-search
LeetCode 3319 - K-th Largest Perfect Subtree Size in Binary Tree

We are given the root of a binary tree and an integer k. Our goal is to find the size of the k-th largest perfect binary subtree contained anywhere within the tree. A perfect binary tree has two defining properties: 1. Every internal node has exactly two children. 2.

leetcodemediumtreedepth-first-searchsortingbinary-tree
LeetCode 2307 - Check for Contradictions in Equations

This problem gives us a collection of equations of the form: Each variable is represented as a string, and each equation defines a multiplicative relationship between two variables. The task is to determine whether all equations can simultaneously be true.

leetcodehardarraydepth-first-searchunion-findgraph-theory
LeetCode 2835 - Minimum Operations to Form Subsequence With Target Sum

The problem presents a 0-indexed array nums of non-negative powers of 2 and an integer target. Each element in nums is guaranteed to be a power of two, which is important because it allows us to reason about sums and splits in terms of binary representation.

leetcodehardarraygreedybit-manipulation
CF 301C - Yaroslav and Algorithm

We must construct a small string rewriting program. The program consists of ordered commands. Each command searches for a substring and replaces its first occurrence with another string. Some commands continue execution after replacement, while others terminate immediately.

codeforcescompetitive-programmingconstructive-algorithms
LeetCode 2883 - Drop Missing Data

This problem provides a pandas DataFrame named students with three columns: | Column | Type | | --- | --- | | studentid | int | | name | object | | age | int | Some rows contain missing values in the name column.

leetcodeeasy
CF 165C - Another Problem on Strings

We are asked to count substrings of a binary string that contain exactly k ones. A substring is any contiguous sequence of characters within the string, and different occurrences at different positions count separately.

codeforcescompetitive-programmingbinary-searchbrute-forcedpmathstringstwo-pointers
LeetCode 2218 - Maximum Value of K Coins From Piles

This problem asks us to maximize the total value of coins collected from multiple piles while following a strict removal rule. Each pile is ordered from top to bottom, meaning we cannot arbitrarily pick any coin in a pile. We may only remove coins from the top, one at a time.

leetcodehardarraydynamic-programmingprefix-sum
LeetCode 2240 - Number of Ways to Buy Pens and Pencils

The problem asks us to determine the number of distinct ways to spend a given amount of money, total, on pens and pencils, each with fixed costs, cost1 for pens and cost2 for pencils.

leetcodemediummathenumeration
LeetCode 2706 - Buy Two Chocolates

The problem is asking us to purchase exactly two chocolates from a store given their individual prices, while ensuring that after buying them we do not end up in debt.

leetcodeeasyarraygreedysorting
CF 350B - Resort

We are given a directed structure on n objects representing a ski resort. Each object is either a mountain or a hotel. Every object has at most one outgoing ski track leading to another object, and a hotel never has outgoing tracks at all.

codeforcescompetitive-programminggraphs
CF 253A - Boys and Girls

We are asked to arrange a sequence consisting of two kinds of objects, boys and girls, into a single line. The only freedom we have is the order.

codeforcescompetitive-programminggreedy
LeetCode 3021 - Alice and Bob Playing Flower Game

The game consists of two flower lanes containing x and y flowers respectively. Alice moves first, and on every turn a player removes exactly one flower from either lane. A very important observation is that the players do not have any meaningful strategic choice.

leetcodemediummath
LeetCode 2761 - Prime Pairs With Target Sum

The problem asks us to find all pairs of prime numbers (x, y) such that both numbers are between 1 and n inclusive, their sum equals n, and x <= y.

leetcodemediumarraymathenumerationnumber-theory
CF 207A2 - Beaver's Calculator 1.0

We are given several independent sequences of integers, one sequence per scientist. Each sequence must be kept in its original internal order, but we are allowed to interleave these sequences arbitrarily when forming one global list.

codeforcescompetitive-programminggreedy
LeetCode 3086 - Minimum Moves to Pick K Ones

The reviewer identified a sign error in the swap argument, so the first task is to determine the correct monotonicity direction before rebuilding the proof. For , there is only one permutation, so the statement is trivial.

leetcodehardarraygreedysliding-windowprefix-sum
LeetCode 2268 - Minimum Number of Keypresses

The problem asks us to determine the minimum number of keypresses required to type a given string s using a keypad with 9 buttons. Each button can map to at most 3 letters, and each letter must be mapped to exactly one button.

leetcodemediumhash-tablestringgreedysortingcounting
LeetCode 2124 - Check if All A's Appears Before All B's

The problem gives us a string s that contains only two possible characters, 'a' and 'b'. We must determine whether every 'a' appears before every 'b'. Another way to think about the requirement is this: once we encounter a 'b', we should never see another 'a' later in the string.

leetcodeeasystring
LeetCode 3062 - Winner of the Linked List Game

The problem gives us the head of a singly linked list whose length is always even. The nodes are grouped into pairs based on their indices: - Nodes at indices (0, 1) form the first pair - Nodes at indices (2, 3) form the second pair - Nodes at indices (4, 5) form the third…

leetcodeeasylinked-list
CF 429B - Working out

We have a two-dimensional gym represented as a grid of size n × m. Each cell contains a positive integer representing the calories burned by doing the workout at that location.

codeforcescompetitive-programmingdp
LeetCode 3222 - Find the Winning Player in Coin Game

The game gives us two types of coins: - x coins worth 75 - y coins worth 10 Two players, Alice and Bob, take turns. Alice always moves first. On every turn, the current player must select coins whose total value is exactly 115.

leetcodeeasymathsimulationgame-theory
CF 415A - Mashmokh and Lights

The factory has a row of lights indexed from left to right. Every light starts in the “on” state. Mashmokh performs a sequence of button presses, and each button has an index that determines how far to the right its effect extends.

codeforcescompetitive-programmingimplementation
LeetCode 2938 - Separate Black and White Balls

The problem asks us to determine the minimum number of adjacent swaps required to rearrange a string of black and white balls such that all white balls (0s) are grouped on the left and all black balls (1s) are grouped on the right.

leetcodemediumtwo-pointersstringgreedy
CF 197B - Limit

We are given two polynomials, $P(x)$ and $Q(x)$, written in descending powers of $x$. The task is to compute: $$lim{x to infty} frac{P(x)}{Q(x)}$$ The input gives the degrees of the two polynomials and all coefficients from the highest-degree term down to the constant term.

codeforcescompetitive-programmingmath
LeetCode 1922 - Count Good Numbers

The problem asks us to count how many digit strings of length n satisfy a specific positional rule. A digit string is considered "good" when: - Every digit placed at an even index, meaning indices 0, 2, 4, ..., must itself be an even digit.

leetcodemediummathrecursion
LeetCode 3232 - Find if Digit Game Can Be Won

The problem presents a simple two-player game between Alice and Bob using an array of positive integers. Each number in the array is either a single-digit number (1 to 9) or a double-digit number (10 to 99).

leetcodeeasyarraymath
LeetCode 3334 - Find the Maximum Factor Score of Array

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

leetcodemediumarraymathnumber-theory
LeetCode 2077 - Paths in Maze That Lead to Same Room

The problem asks us to analyze a maze represented as an undirected graph of n rooms connected by corridors. Each corridor allows travel in both directions, and the input corridors lists all such connections.

leetcodemediumgraph-theory
LeetCode 2288 - Apply Discount to Prices

The problem asks us to process a string representing a sentence containing words and prices, where prices are words that start with a dollar sign 1e5 or 5$) should remain unchanged.

leetcodemediumstring
CF 412D - Giving Awards

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

codeforcescompetitive-programmingdfs-and-similar
LeetCode 3091 - Apply Operations to Make Sum of Array Greater Than or Equal to k

The problem gives us a single positive integer k. We start with an array containing exactly one element: We are allowed to perform two kinds of operations any number of times: 1. Increase the value of any existing element by 1 2.

leetcodemediummathgreedyenumeration
CF 182C - Optimal Sum

We have an array and a fixed window length len. For every subarray of length len, we compute its sum and then take the absolute value. The "optimal sum" of the whole array is the maximum absolute subarray sum among all windows of that fixed length.

codeforcescompetitive-programmingdata-structuresgreedy
LeetCode 2166 - Design Bitset

This problem asks us to design a custom Bitset data structure that supports several operations efficiently. A bitset is simply a sequence of binary values, where each position stores either 0 or 1.

leetcodemediumarrayhash-tablestringdesign
LeetCode 2620 - Counter

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

leetcodeeasy
CF 151A - Soft Drinking

A group of friends wants to make identical toasts using three resources: soft drink, lime slices, and salt. Every toast consumes a fixed amount of each resource. The task is to determine how many complete toasts each friend can make before at least one resource runs out.

codeforcescompetitive-programmingimplementationmath
CF 429D - Tricky Function

We are given an array of integers a with n elements. The task is to select two distinct indices i and j and compute a function f(i, j) that combines both the squared distance between the indices and the squared sum of the elements strictly between them.

codeforcescompetitive-programmingdata-structuresdivide-and-conquergeometry
LeetCode 2675 - Array of Objects to Matrix

The problem is asking us to transform a JSON-like array of objects or arrays into a matrix representation. Each row of the resulting matrix corresponds to one object (or array) in the input array, and the first row contains the column names.

leetcodehard
LeetCode 2190 - Most Frequent Number Following Key In an Array

The problem asks us to find the integer that appears most frequently immediately after a given key value in the array. More specifically, we are given an integer array nums and an integer key, which is guaranteed to exist in the array.

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

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

leetcodemediumarrayhash-tabledesignheap-(priority-queue)matrixordered-set
LeetCode 2473 - Minimum Cost to Buy Apples

The problem asks us to determine the minimum cost to buy exactly one apple starting from each city in a network of cities connected by bidirectional roads. Each city has a specific cost for buying an apple, and each road has a travel cost.

leetcodemediumarraygraph-theoryheap-(priority-queue)shortest-path
LeetCode 2791 - Count Paths That Can Form a Palindrome in a Tree

I can do that, but the guide will be very long for a single chat response because your required format includes detailed prose, brute force and optimal approaches, proof sketch, Python and Go implementations, worked traces for every example, complexity analysis, comprehensive…

leetcodehardhash-tablebit-manipulationtreedepth-first-search
LeetCode 3133 - Minimum Array End

The problem asks us to construct a strictly increasing array nums of length n such that the bitwise AND of all elements equals x. Among all valid arrays, we want to minimize the last element, nums[n - 1]. The constraints are important: - Every element must be a positive integer.

leetcodemediumbit-manipulation
CF 189B - Counting Rhombi

We are asked to count rhombi inside a rectangle of width w and height h, where each rhombus has its vertices on integer coordinates and diagonals aligned with the axes. Each rhombus must have positive area and be fully contained in the rectangle.

codeforcescompetitive-programmingbrute-forcemath
LeetCode 2920 - Maximum Points After Collecting Coins From All Nodes

We are given a tree with n nodes rooted at node 0. Each node contains a certain number of coins. We must collect coins from every node while respecting the tree hierarchy, meaning a node can only be processed after all of its ancestors have already been processed.

leetcodehardarraydynamic-programmingbit-manipulationtreedepth-first-searchmemoization
LeetCode 2417 - Closest Fair Integer

In this problem, we are given a positive integer n, and we must find the smallest integer greater than or equal to n that is considered "fair". A number is fair when the count of even digits is exactly equal to the count of odd digits.

leetcodemediummathenumeration
LeetCode 3032 - Count Numbers With Unique Digits II

The problem asks us to count how many integers in the inclusive range [a, b] contain only unique digits. A number has unique digits if no digit appears more than once within that number. For example, the number 123 has unique digits because 1, 2, and 3 each appear exactly once.

leetcodeeasyhash-tablemathdynamic-programming
CF 201C - Fragile Bridges

We have a path graph with n platforms and n - 1 bridges between consecutive platforms. Bridge i connects platform i and i + 1, and can be crossed exactly a[i] times before disappearing permanently.

codeforcescompetitive-programmingdp
LeetCode 3114 - Latest Time You Can Obtain After Replacing Characters

The problem gives us a string representing a time in 12-hour format using the pattern "HH:MM". Some characters may already be fixed digits, while others are replaced with "?". Our task is to replace every "?

leetcodeeasystringenumeration
LeetCode 3047 - Find the Largest Area of Square Inside Two Rectangles

The problem asks us to find the largest square that can fit inside the overlapping region of at least two rectangles on a 2D plane. Each rectangle is axis-aligned, meaning its sides are parallel to the x-axis and y-axis.

leetcodemediumarraymathgeometry
LeetCode 2604 - Minimum Time to Eat All Grains

The problem asks us to determine the minimum time needed for all hens to eat all grains when both hens and grains are located on a one-dimensional line.

leetcodehardarraytwo-pointersbinary-searchsorting
LeetCode 2957 - Remove Adjacent Almost-Equal Characters

We are given a string word consisting of lowercase English letters. Two adjacent characters are considered almost-equal if either: - They are exactly the same, such as 'a' and 'a' - Their positions in the alphabet differ by exactly one, such as 'a' and 'b', 'c' and 'b', 'x'…

leetcodemediumstringdynamic-programminggreedy
LeetCode 3150 - Invalid Tweets II

The problem gives us a database table named Tweets with two columns: | Column | Description | | --- | --- | | tweetid | Unique identifier for each tweet | | content | The text content of the tweet | We need to identify all tweets that are considered invalid.

leetcodeeasydatabase
LeetCode 3080 - Mark Elements on Array by Performing Queries

Here’s a fully detailed technical solution guide for LeetCode 3080 following your requested format. The problem gives a zero-indexed array nums of size n consisting of positive integers and a 2D array queries of size m where each query is [indexi, ki].

leetcodemediumarrayhash-tablesortingheap-(priority-queue)simulation
LeetCode 1908 - Game of Nim

This problem is the classic mathematical game known as Nim. We are given an array piles, where each element represents the number of stones in a pile. Two players, Alice and Bob, take turns removing stones.

leetcodemediumarraymathdynamic-programmingbit-manipulationbrainteasergame-theory
CF 165E - Compatible Numbers

We are given an array of integers, and for every element we must find another array element whose bitwise AND with it is zero. Two numbers are compatible exactly when they do not share any bit set to 1.

codeforcescompetitive-programmingbitmasksbrute-forcedfs-and-similardp
LeetCode 3096 - Minimum Levels to Gain More Points

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

leetcodemediumarrayprefix-sum
LeetCode 2904 - Shortest and Lexicographically Smallest Beautiful String

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

leetcodemediumstringsliding-window
CF 192A - Funky Numbers

This is a Type A - “Find all X” problem. A valid proof must do two things: 1. Verify that every claimed solution actually satisfies the conditions. 2. Prove that no other solutions exist. The proposed solution does not complete either direction fully.

codeforcescompetitive-programmingbinary-searchbrute-forceimplementation
LeetCode 3293 - Calculate Product Final Price

The problem asks us to calculate the final price for each product in a database, taking into account any category-specific discounts. We are given two tables: Products and Discounts. The Products table contains each product's unique ID, its category, and its original price.

leetcodemediumdatabase
LeetCode 3165 - Maximum Sum of Subsequence With Non-adjacent Elements

This problem asks us to process a sequence of update queries on an array. After each update, we must compute the maximum possible sum of a subsequence where no two selected elements are adjacent in the array. The key detail is that the subsequence does not need to be contiguous.

leetcodehardarraydivide-and-conquerdynamic-programmingsegment-tree
LeetCode 3238 - Find the Number of Winning Players

The problem gives us n players and a list called pick, where each entry is of the form [xi, yi]. This means player xi picked a ball with color yi. A player wins if they have picked strictly more than their player index number of balls of the same color.

leetcodeeasyarrayhash-tablecounting
LeetCode 2495 - Number of Subarrays Having Even Product

The problem gives us an integer array nums and asks us to count how many contiguous subarrays have an even product. A subarray is a continuous segment of the array. For each possible subarray, we compute the product of all its elements.

leetcodemediumarraymathdynamic-programming
LeetCode 2367 - Number of Arithmetic Triplets

The problem requires us to find the number of arithmetic triplets in a strictly increasing array of integers. An arithmetic triplet (i, j, k) satisfies the conditions i < j < k, nums[j] - nums[i] == diff, and nums[k] - nums[j] == diff.

leetcodeeasyarrayhash-tabletwo-pointersenumeration
CF 166E - Tetrahedron

We are asked to count the number of ways an ant can start at vertex D of a tetrahedron and return to D after exactly n steps, moving along edges at every step. The tetrahedron has four vertices labeled A, B, C, D, and each vertex is connected to the other three.

codeforcescompetitive-programmingdpmathmatrices
CF 240E - Road Repairs

We have a directed graph of cities and roads. City 1 is the capital. Every road is either already usable or broken. A broken road may be repaired, after which it behaves like a normal directed edge. The government wants every city to become reachable from the capital.

codeforcescompetitive-programmingdfs-and-similargraphsgreedy
LeetCode 1939 - Users That Actively Request Confirmation Messages

This problem asks us to identify users who requested confirmation messages at least twice within a 24 hour time window. We are given two database tables: The Signups table contains one row per user and records when the user signed up. The userid column is unique.

leetcodeeasydatabase
CF 200C - Football Championship

We have a four-team football group where every pair of teams plays exactly once, so the full tournament contains six matches. Five results are already known, and the only remaining match is the one involving BERLAND. Each match contributes points in the usual way.

codeforcescompetitive-programmingbrute-forceimplementation
LeetCode 2158 - Amount of New Area Painted Each Day

This problem describes a painting scenario represented as a one-dimensional number line. Each element in the input array paint[i] = [starti, endi] represents the section that needs to be painted on the ith day.

leetcodehardarraysegment-treeordered-set
LeetCode 3235 - Check if the Rectangle Corner Is Reachable

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

leetcodehardarraymathdepth-first-searchbreadth-first-searchunion-findgeometry