brain

tamnd's digital brain — notes, problems, research

42623 notes

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 3297 - Count Substrings That Can Be Rearranged to Contain a String I

We are given two lowercase strings, word1 and word2. A substring of word1 is considered valid if its characters can be rearranged so that word2 becomes a prefix of the rearranged string. To understand what this means, suppose word2 = "abc".

leetcodemediumhash-tablestringsliding-window
LeetCode 2302 - Count Subarrays With Score Less Than K

The problem asks us to count the number of contiguous subarrays of a given array nums whose score is strictly less than a given threshold k. The score of a subarray is defined as the product of its sum and its length.

leetcodehardarraybinary-searchsliding-windowprefix-sum
CF 256E - Lucky Arrays

We are given an array of length n, initially filled with zeroes. Each query sets a single element to a value between 0 and 3. Zero represents an unset element, while 1, 2, or 3 are actual values.

codeforcescompetitive-programmingdata-structures
CF 431C - k-Tree

We are working with a rooted infinite tree where every node always has exactly $k$ outgoing edges to children. Each of those $k$ edges has a fixed weight: the first is 1, the second is 2, and so on up to $k$.

codeforcescompetitive-programmingdpimplementationtrees
LeetCode 2911 - Minimum Changes to Make K Semi-palindromes

The problem asks us to partition a given string s into k contiguous substrings and modify the characters minimally so that each substring becomes a semi-palindrome.

leetcodehardtwo-pointersstringdynamic-programming
LeetCode 3082 - Find the Sum of the Power of All Subsequences

You are given an array nums and an integer k. For every subsequence of nums, we define its power as the number of subsequences inside it whose sum equals k. The task is to compute the total power across all subsequences of the original array.

leetcodehardarraydynamic-programming
LeetCode 1872 - Stone Game VIII

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

leetcodehardarraymathdynamic-programmingprefix-sumgame-theory
LeetCode 2264 - Largest 3-Same-Digit Number in String

The problem requires identifying the largest "good" integer from a given string of digits. A "good" integer is defined as a substring of length 3 where all digits are identical.

leetcodeeasystring
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
LeetCode 2642 - Design Graph With Shortest Path Calculator

The problem asks us to design a graph data structure that supports two operations efficiently: 1. Dynamically adding directed weighted edges. 2. Finding the shortest path cost between two nodes. We are given a directed weighted graph with n nodes labeled from 0 to n - 1.

leetcodehardgraph-theorydesignheap-(priority-queue)shortest-path
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
LeetCode 2568 - Minimum Impossible OR

The problem asks us to find the smallest positive integer that cannot be represented as a bitwise OR of any subsequence of a given array nums. The input array contains positive integers, and the subsequences can have any length, including length 1.

leetcodemediumarraybit-manipulationbrainteaser
LeetCode 2612 - Minimum Reverse Operations

This will be a very large, multi-thousand-word technical guide because of the required depth, full proofs, worked examples, Python and Go implementations, detailed walkthroughs, complexity reasoning, and exhaustive tests.

leetcodehardarrayhash-tablebreadth-first-searchunion-findordered-set
CF 416D - Population Size

We are given a sequence of length $n$, where each position is either a fixed positive integer or unknown (marked as $-1$). The task is to interpret this sequence as being formed by concatenating several arithmetic progressions, one after another.

codeforcescompetitive-programminggreedyimplementationmath
LeetCode 1875 - Group Employees of the Same Salary

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

leetcodemediumdatabase
CF 263E - Rhombus

We are given a rectangular grid of non-negative integers. For every valid center cell (x, y), we define a diamond-shaped region of radius k - 1. The function f(x, y) is the sum of all values inside that rhombus. The task is not to compute every value explicitly and print them.

codeforcescompetitive-programmingbrute-forcedata-structuresdp
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 2950 - Number of Divisible Substrings

The problem asks us to analyze a given string word where each lowercase English letter is mapped to a digit according to a classic phone keypad scheme.

leetcodemediumhash-tablestringcountingprefix-sum
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
LeetCode 2360 - Longest Cycle in a Graph

This problem gives us a directed graph represented by an array called edges. The graph contains n nodes labeled from 0 to n - 1. Each node has at most one outgoing edge.

leetcodeharddepth-first-searchbreadth-first-searchgraph-theorytopological-sort
CF 203D - Hit Ball

We are asked to simulate a three-dimensional billiard-like scenario where a ball travels inside a rectangular corridor with perfectly reflecting walls, floor, and ceiling.

codeforcescompetitive-programminggeometryimplementationmath
LeetCode 2499 - Minimum Total Cost to Make Arrays Unequal

You are given two arrays, nums1 and nums2, both of length n. You are allowed to perform operations only on nums1. In a single operation, you may swap any two indices in nums1, and the cost of that operation is the sum of the two indices involved in the swap.

leetcodehardarrayhash-tablegreedycounting
LeetCode 2478 - Number of Beautiful Partitions

The problem asks us to count the number of ways to split a given string s of digits into exactly k non-overlapping substrings, where each substring satisfies specific rules: it must start with a prime digit (2, 3, 5, 7), end with a non-prime digit (1, 4, 6, 8, 9), and have…

leetcodehardstringdynamic-programmingprefix-sum
CF 437E - The Child and Polygon

We are asked to count how many ways a simple polygon with $n$ vertices can be triangulated. Triangulation here means splitting the polygon into triangles that exactly cover the polygon without overlap and without introducing new points.

codeforcescompetitive-programmingdpgeometry
CF 447B - DZY Loves Strings

We are given a string made of lowercase letters and a way to assign a numerical weight to each letter. The value of a full string is computed by summing, over all positions, the product of the position index (starting from 1) and the weight of the character at that position.

codeforcescompetitive-programminggreedyimplementation
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 3245 - Alternating Groups III

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

leetcodehardarraybinary-indexed-treeordered-set
LeetCode 2815 - Max Pair Sum in an Array

The problem gives us an array of integers nums. For every number, we can determine its largest digit. For example: - 2536 has digits 2, 5, 3, 6, so its largest digit is 6 - 112 has digits 1, 1, 2, so its largest digit is 2 - 71 has digits 7, 1, so its largest digit is 7 We…

leetcodeeasyarrayhash-table
CF 212E - IT Restaurants

We are asked to place two types of restaurants on a tree-shaped city map in such a way that no two adjacent junctions host different types, each junction hosts at most one restaurant, and each network has at least one restaurant.

codeforcescompetitive-programmingdfs-and-similardptrees
LeetCode 1858 - Longest Word With All Prefixes

The problem gives us an array of lowercase strings called words. We need to find the longest word such that every prefix of that word also exists in the array. A prefix means the string formed by taking characters from the beginning of the word.

leetcodemediumarraystringdepth-first-searchtrie
CF 169B - Replacing Digits

We are given a decimal number as a string and another string containing extra digits that we may use for replacements. Every digit from the second string can be used at most once. For each chosen digit, we may replace any single position in the original number.

codeforcescompetitive-programminggreedy
LeetCode 2895 - Minimum Processing Time

This problem gives us two arrays: - processorTime, where each value represents the time when a processor becomes available - tasks, where each value represents how long a task takes to execute Each processor has exactly 4 cores, and each core can execute exactly one task.

leetcodemediumarraygreedysorting
LeetCode 2467 - Most Profitable Path in a Tree

The problem presents a rooted tree with n nodes numbered from 0 to n-1, where node 0 is the root. Each node has a gate that can either cost money to open (negative value) or give a reward (positive value). Alice starts at the root, and Bob starts at a specified node.

leetcodemediumarraytreedepth-first-searchbreadth-first-searchgraph-theory
CF 145D - Lucky Pair

We are given an array of integers, and some of these integers are "lucky numbers," meaning they consist only of the digits 4 and 7.

codeforcescompetitive-programmingcombinatoricsdata-structuresimplementation
LeetCode 3341 - Find Minimum Time to Reach Last Room I

The problem is asking for the minimum time required to reach the bottom-right room (n - 1, m - 1) in a dungeon represented as an n x m grid. Each room (i, j) has a moveTime[i][j], which specifies the earliest time at which the room can be entered.

leetcodemediumarraygraph-theoryheap-(priority-queue)matrixshortest-path
CF 241B - Friends

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

codeforcescompetitive-programmingbinary-searchbitmasksdata-structuresmath
LeetCode 3129 - Find All Possible Stable Binary Arrays I

In this problem, we need to count how many binary arrays can be formed using exactly zero copies of 0 and exactly one copies of 1, while satisfying an additional stability condition.

leetcodemediumdynamic-programmingprefix-sum
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 2641 - Cousins in Binary Tree II

The problem gives us the root of a binary tree and asks us to replace every node’s value with the sum of all of its cousins’ values.

leetcodemediumhash-tabletreedepth-first-searchbreadth-first-searchbinary-tree
LeetCode 3181 - Maximum Total Reward Using Operations II

The problem gives us an array rewardValues, where each element represents a reward we may choose exactly once. We begin with a total reward x = 0, and we are allowed to repeatedly pick an unmarked element only if its value is strictly greater than the current total reward.

leetcodehardarraydynamic-programmingbit-manipulation
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 2163 - Minimum Difference in Sums After Removal of Elements

The array contains exactly 3 n elements. We must remove exactly n elements, leaving 2 n elements behind. The remaining elements keep their original relative order because we are removing a subsequence, not rearranging the array.

leetcodehardarraydynamic-programmingheap-(priority-queue)
LeetCode 2299 - Strong Password Checker II

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

leetcodeeasystring
LeetCode 2931 - Maximum Spending After Buying Items

We are given an m × n matrix values where each row represents a shop and each column represents an item in that shop. The important property is that every row is sorted in non-increasing order: When buying from a shop, we are not allowed to choose any arbitrary item.

leetcodehardarraygreedysortingheap-(priority-queue)matrix
LeetCode 2754 - Bind Function to Context

The problem is asking us to implement a polyfill for JavaScript's built-in Function.prototype.bind method. Specifically, we need to create a bindPolyfill method that can be called on any function.

leetcodemedium
CF 166C - Median

We start with an array of integers and a target value x. We may append any number of extra integers to the array, and we want the median of the final array to become exactly x. The task is to compute the smallest number of added elements needed to make that happen.

codeforcescompetitive-programminggreedymathsortings
LeetCode 2884 - Modify Columns

The problem provides a Pandas DataFrame named employees with two columns: | Column | Type | | --- | --- | | name | object | | salary | int | Each row represents one employee and their current salary.

leetcodeeasy
LeetCode 2653 - Sliding Subarray Beauty

The problem asks us to compute the beauty of every contiguous subarray of size k within a given integer array nums. The beauty of a subarray is defined as the xth smallest negative number in that subarray. If a subarray contains fewer than x negative numbers, the beauty is 0.

leetcodemediumarrayhash-tablesliding-window
LeetCode 2149 - Rearrange Array Elements by Sign

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

leetcodemediumarraytwo-pointerssimulation
LeetCode 2349 - Design a Number Container System

The problem asks us to design a data structure that supports two operations efficiently: 1. Assign a number to a given index. 2. Find the smallest index currently assigned to a given number.

leetcodemediumhash-tabledesignheap-(priority-queue)ordered-set
CF 174B - File List

We are given one long string that originally consisted of several file names written back to back with no separators. Every valid file name must look like name.ext. The rules are strict. The part before the dot contains only lowercase letters and has length from 1 to 8.

codeforcescompetitive-programmingdpgreedyimplementation
LeetCode 2454 - Next Greater Element IV

The problem asks us to compute, for every element in the array, its "second greater element" to the right. For an index i, we are interested in elements positioned after i. Among those elements, we only care about values strictly greater than nums[i].

leetcodehardarraybinary-searchstacksortingheap-(priority-queue)monotonic-stack
LeetCode 2937 - Make Three Strings Equal

The problem asks us to make three strings s1, s2, and s3 identical by repeatedly deleting their rightmost characters. Each deletion is counted as one operation. The key restriction is that we cannot completely delete a string, so at least one character must remain in each string.

leetcodeeasystring
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 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 196B - Infinite Maze

We are given a finite maze of size n × m. Some cells are walls, some are open, and one cell contains the starting position S. The maze is not used only once.

codeforcescompetitive-programmingdfs-and-similargraphs
LeetCode 3039 - Apply Operations to Make String Empty

The problem gives us a lowercase string s and defines a repeated operation. During one operation, we scan through all letters from 'a' to 'z'. For each letter, if that letter appears in the current string, we remove its first occurrence.

leetcodemediumarrayhash-tablesortingcounting
LeetCode 3095 - Shortest Subarray With OR at Least K I

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

leetcodeeasyarraybit-manipulationsliding-window
LeetCode 3282 - Reach End of Array With Max Score

We are given an integer array nums, where each position represents a possible jump starting point. We begin at index 0 and must eventually reach index n - 1. From any index i, we may jump to any later index j where j i.

leetcodemediumarraygreedy
LeetCode 2828 - Check if a String Is an Acronym of Words

This problem asks us to determine whether a given string s is exactly the acronym formed from an array of words. An acronym is created by taking the first character from each word in the words array and concatenating those characters in the same order as the words appear.

leetcodeeasyarraystring
LeetCode 3007 - Maximum Number That Sum of the Prices Is Less Than or Equal to K

The problem asks us to find the largest integer num such that the accumulated price of all numbers from 1 to num does not exceed a given threshold k.

leetcodemediummathbinary-searchdynamic-programmingbit-manipulation
LeetCode 2093 - Minimum Cost to Reach City With Discounts

This problem describes a weighted, undirected graph where each city is a node and each highway is an edge with an associated toll cost. The goal is to travel from city 0 to city n - 1 while minimizing the total travel cost. The special twist is the presence of discounts.

leetcodemediumgraph-theoryheap-(priority-queue)shortest-path
LeetCode 2340 - Minimum Adjacent Swaps to Make a Valid Array

The previous solution fails immediately under a counterexample check. The proposed path was the union of the segments from to the midpoints of and . If the side length is , then the detector radius is The distance from to that path is , while Hence is not detected at all.

leetcodemediumarraygreedy
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
CF 142A - Help Farmer

After the theft, the barn contains a smaller rectangular box of hay blocks. If the original dimensions were $A times B times C$, then the remaining pile has dimensions $(A-1) times (B-2) times (C-2)$.

codeforcescompetitive-programmingbrute-forcemath
CF 245F - Log Stream Analysis

We are given a chronologically ordered stream of log entries, where each entry has an exact timestamp down to the second and an associated message describing a program warning.

codeforcescompetitive-programmingbinary-searchbrute-forceimplementationstrings
LeetCode 2781 - Length of the Longest Valid Substring

The problem gives us a string word and a list of forbidden strings forbidden. A substring is considered valid if none of its internal substrings appear in the forbidden list.

leetcodehardarrayhash-tablestringsliding-window
LeetCode 2117 - Abbreviating the Product of a Range

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

leetcodehardmathnumber-theory
LeetCode 2774 - Array Upper Bound

The problem asks us to enhance JavaScript arrays with a method called upperBound(). Given a sorted array of numbers and a target value, the method should return the last index where the target appears. If the target does not exist in the array, the method should return -1.

leetcodeeasy
LeetCode 1856 - Maximum Subarray Min-Product

The problem asks us to find the maximum min-product of any contiguous subarray of a given integer array nums. The min-product of a subarray is defined as the minimum value in that subarray multiplied by the sum of all elements in that subarray.

leetcodemediumarraystackmonotonic-stackprefix-sum
LeetCode 3023 - Find Pattern in Infinite Stream I

The problem asks us to detect the first occurrence of a given binary pattern within an infinite stream of bits. We are given an object stream that allows us to read one bit at a time using the next() function.

leetcodemediumarraysliding-windowrolling-hashstring-matchinginteractivehash-function
LeetCode 2732 - Find a Good Subset of the Matrix

The problem asks us to find a subset of rows in a binary matrix where each column’s sum in that subset is at most half of the number of rows chosen, rounded down.

leetcodehardarrayhash-tablebit-manipulationmatrix
CF 431D - Random Task

We need to find a positive integer n such that inside the interval (n, 2n], exactly m numbers have exactly k ones in their binary representation.

codeforcescompetitive-programmingbinary-searchbitmaskscombinatoricsdpmath
LeetCode 3386 - Button with Longest Push Time

The problem gives us a sequence of keyboard button press events. Each event is represented as: Here: - index is the identifier of the button that was pressed. - time is the moment when the press happened.

leetcodeeasyarray
LeetCode 2397 - Maximum Rows Covered by Columns

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

leetcodemediumarraybacktrackingbit-manipulationmatrixenumeration
LeetCode 2310 - Sum of Numbers With Units Digit K

This problem asks us to construct a set of positive integers such that: 1. Every number in the set has a units digit equal to k. 2. The sum of all numbers equals num. 3. We want the smallest possible number of integers in the set.

leetcodemediummathdynamic-programminggreedyenumeration
LeetCode 2444 - Count Subarrays With Fixed Bounds

This problem asks us to count how many contiguous subarrays satisfy two exact boundary conditions at the same time: 1. The minimum element in the subarray must be exactly minK. 2. The maximum element in the subarray must be exactly maxK.

leetcodehardarrayqueuesliding-windowmonotonic-queue
LeetCode 2060 - Check if an Original String Exists Given Two Encoded Strings

The problem is asking us to determine whether there exists a single original string that could have been encoded into two different given strings, s1 and s2. Each encoded string may contain letters and digits.

leetcodehardstringdynamic-programming
LeetCode 3035 - Maximum Palindromes After Operations

This problem gives us an array of strings, words, and allows us to swap any character with any other character across the entire collection of strings. The swaps are completely unrestricted.

leetcodemediumarrayhash-tablestringgreedysortingcounting
CF 182B - Vasya's Calendar

We are asked to simulate a peculiar kind of calendar. Vasya has a clock that shows days from 1 to d. Each month has a certain number of days, and the clock does not know which month it is.

codeforcescompetitive-programmingimplementation
LeetCode 2923 - Find Champion I

This problem describes a tournament of n teams, where every pair of teams has a clear winner. The input is given as a square matrix called grid, where grid[i][j] tells us whether team i is stronger than team j.

leetcodeeasyarraymatrix
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
LeetCode 3049 - Earliest Second to Mark Indices II

We are given two arrays: - nums, where nums[i] represents the initial value associated with index i + 1 - changeIndices, where at second s, we are allowed to perform a special operation on index changeIndices[s] Every index in nums starts as unmarked.

leetcodehardarraybinary-searchgreedyheap-(priority-queue)
CF 250B - Restoring IPv6

An IPv6 address in its full form is a fixed structure made of eight blocks. Each block represents 16 bits and is written as exactly four hexadecimal characters, including leading zeros when necessary.

codeforcescompetitive-programmingimplementationstrings
LeetCode 1862 - Sum of Floored Pairs

The problem asks us to calculate the sum of the integer division results, floor(nums[i] / nums[j]), for every pair of elements (i, j) in a given array nums. Here, floor() represents the largest integer less than or equal to the division result.

leetcodehardarraymathbinary-searchcountingenumerationprefix-sum
LeetCode 3307 - Find the K-th Character in String Game II

The problem describes a string manipulation game between Alice and Bob. Initially, Alice starts with a string word = "a". Bob provides a list of operations, represented by the integer array operations.

leetcodehardmathbit-manipulationrecursion
CF 302A - Eugeny and Array

We are given an array containing only 1 and -1. For every query [l, r], we look at the subarray from index l to r.

codeforcescompetitive-programmingimplementation
LeetCode 2256 - Minimum Average Difference

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

leetcodemediumarrayprefix-sum
LeetCode 2871 - Split Array Into Maximum Number of Subarrays

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

leetcodemediumarraygreedybit-manipulation
LeetCode 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 3275 - K-th Nearest Obstacle Queries

The problem requires tracking obstacles on an infinite 2D plane and answering, after each obstacle is placed, the distance to the k-th nearest obstacle from the origin (0, 0) based on Manhattan distance, defined as |x| + |y|.

leetcodemediumarrayheap-(priority-queue)
LeetCode 2073 - Time Needed to Buy Tickets

This problem describes a queue of n people, each wanting to buy a certain number of tickets. The input is an array tickets where tickets[i] represents how many tickets the i-th person wants.

leetcodeeasyarrayqueuesimulation
LeetCode 1889 - Minimum Space Wasted From Packaging

The problem gives us a list of package sizes and several suppliers. Each supplier offers an unlimited number of boxes, but only in certain fixed sizes. We must choose exactly one supplier and pack every package using only the box sizes that supplier provides.

leetcodehardarraybinary-searchsortingprefix-sum
LeetCode 2997 - Minimum Number of Operations to Make Array XOR Equal to K

This problem asks us to transform an array so that the bitwise XOR of all elements becomes exactly k, while minimizing the number of operations. An operation consists of selecting any element in the array and flipping exactly one bit in its binary representation.

leetcodemediumarraybit-manipulation
LeetCode 2443 - Sum of Number and Its Reverse

Here’s a complete, detailed solution guide for LeetCode 2443 - Sum of Number and Its Reverse, fully following your formatting rules.

leetcodemediummathenumeration
LeetCode 3118 - Friday Purchase III

This problem asks us to calculate the total amount of money spent by Premium and VIP members on Fridays of each week in November 2023.

leetcodemediumdatabase
CF 263A - Beautiful Matrix

We are given a fixed 5 by 5 grid that contains mostly zeros and exactly one cell containing a one. In one move, we are allowed to swap adjacent rows or swap adjacent columns. Each such swap moves the entire row or column by exactly one position.

codeforcescompetitive-programmingimplementation
CF 171C - A Piece of Cake

The input is a sequence of integers. The first number tells us how many additional integers follow. If the sequence is: then there are four values: 1, 2, 3, 4. The task itself is intentionally disguised by the strange statement.

codeforcescompetitive-programming*specialimplementation
LeetCode 2745 - Construct the Longest New String

The problem gives us three types of fixed two-character strings: - "AA" appears x times - "BB" appears y times - "AB" appears z times We may choose any subset of these strings and concatenate them in any order.

leetcodemediummathdynamic-programminggreedybrainteaser