brain

tamnd's digital brain — notes, problems, research

42616 notes

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 2177 - Find Three Consecutive Integers That Sum to a Given Number

This problem asks us to determine whether a given integer num can be represented as the sum of three consecutive integers. If such a representation exists, we must return those three integers in sorted order. Otherwise, we return an empty array.

leetcodemediummathsimulation
CF 155A - I_love_\%username\%

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

codeforcescompetitive-programmingbrute-force
LeetCode 2108 - Find First Palindromic String in the Array

The problem asks us to examine an array of strings, words, and identify the first string that is a palindrome. A palindrome is a string that reads the same forward and backward.

leetcodeeasyarraytwo-pointersstring
LeetCode 2075 - Decode the Slanted Ciphertext

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

leetcodemediumstringsimulation
LeetCode 2609 - Find the Longest Balanced Substring of a Binary String

The problem gives us a binary string s, which means the string contains only the characters '0' and '1'. We need to find the length of the longest substring that is considered balanced. A substring is balanced when two conditions are satisfied: 1.

leetcodeeasystring
LeetCode 2888 - Reshape Data: Concatenate

The problem is asking us to vertically concatenate two DataFrames into a single unified DataFrame. In simpler terms, given two tables df1 and df2 with identical columns and types, we need to stack the rows of df2 below the rows of df1.

leetcodeeasy
LeetCode 2109 - Adding Spaces to a String

The problem requires us to insert spaces into a given string s at specific positions described by the array spaces. Each element in spaces represents an index in the string before which a space should be inserted.

leetcodemediumarraytwo-pointersstringsimulation
LeetCode 3203 - Find Minimum Diameter After Merging Two Trees

We are given two separate undirected trees. The first tree contains n nodes and is represented by edges1, while the second tree contains m nodes and is represented by edges2. A tree is a connected graph with no cycles.

leetcodehardtreedepth-first-searchbreadth-first-searchgraph-theory
LeetCode 3104 - Find Longest Self-Contained Substring

The problem asks us to find the longest self-contained substring in a given string s. A substring is self-contained if it does not share any characters with the rest of the string.

leetcodehardhash-tablestringsorting
LeetCode 2295 - Replace Elements in an Array

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

leetcodemediumarrayhash-tablesimulation
LeetCode 3090 - Maximum Length Substring With Two Occurrences

The problem is asking for the maximum length of a substring in a given string s such that no character occurs more than twice within that substring. In other words, for any valid substring, each character can appear at most two times.

leetcodeeasyhash-tablestringsliding-window
LeetCode 2922 - Market Analysis III

The problem asks us to analyze three relational tables: Users, Items, and Orders. Each user (seller) has a favorite brand, each item has a brand, and orders record which seller sold which item on which date.

leetcodemediumdatabase
LeetCode 2741 - Special Permutations

The problem asks us to count the number of special permutations of a given array of distinct positive integers nums.

leetcodemediumarraydynamic-programmingbit-manipulationbitmask
LeetCode 3137 - Minimum Number of Operations to Make Word K-Periodic

The problem asks us to transform a given string word of length n into a k-periodic string using the minimum number of operations. A string is k-periodic if it can be formed by repeating a substring s of length k multiple times.

leetcodemediumhash-tablestringcounting
LeetCode 2070 - Most Beautiful Item for Each Query

The problem gives us a list of items, where each item has two properties: - price - beauty Each entry looks like: We are also given a list of queries.

leetcodemediumarraybinary-searchsorting
LeetCode 2837 - Total Traveled Distance

The problem requires calculating the total distance traveled by each user based on ride data stored in a relational database. We are given two tables: Users and Rides. The Users table contains userid and name, where userid is unique.

leetcodeeasydatabase
LeetCode 2714 - Find Shortest Path with K Hops

This problem gives us an undirected weighted graph with n nodes and a list of weighted edges. Each edge connects two nodes and has a positive weight. We are also given a source node s, a destination node d, and an integer k.

leetcodehardgraph-theoryheap-(priority-queue)shortest-path
LeetCode 2613 - Beautiful Pairs

The problem asks us to find a beautiful pair of indices (i, j) in two integer arrays nums1 and nums2 of equal length. A pair (i, j) is beautiful if it minimizes the sum of the absolute differences between the corresponding elements: among all possible pairs where i < j.

leetcodehardarraymathdivide-and-conquergeometrysortingordered-set
LeetCode 2407 - Longest Increasing Subsequence II

The problem asks us to find the length of the longest subsequence in an integer array nums such that the subsequence is strictly increasing and the difference between consecutive elements does not exceed a given integer k.

leetcodehardarraydivide-and-conquerdynamic-programmingbinary-indexed-treesegment-treequeuemonotonic-queue
CF 245C - Game with Coins

We are given a line of numbered chests, each containing some number of coins. On each move, a player chooses an integer position $x$, and that move simultaneously affects three specific chests: $x$, $2x$, and $2x+1$. From each of these chests, one coin is removed if it exists.

codeforcescompetitive-programminggreedy
LeetCode 2278 - Percentage of Letter in String

This problem asks us to calculate the percentage of a given character, letter, in a string s, and return it as an integer rounded down to the nearest whole percent.

leetcodeeasystring
LeetCode 2201 - Count Artifacts That Can Be Extracted

This problem models an excavation process on a square n x n grid. Several rectangular artifacts are buried in the grid, and each artifact occupies one or more cells.

leetcodemediumarrayhash-tablesimulation
LeetCode 2802 - Find The K-th Lucky Number

This problem asks us to find the k-th lucky number, where a lucky number is defined as an integer consisting only of the digits 4 and 7. For example, the sequence of lucky numbers in increasing order starts as 4, 7, 44, 47, 74, 77, 444, and so on.

leetcodemediummathstringbit-manipulation
CF 245A - System Administrator

Polycarpus is running a simple monitoring routine for two servers, which we can call server a and server b. Each "ping" command sends exactly ten packets to one of the servers.

codeforcescompetitive-programmingimplementation
LeetCode 3228 - Maximum Number of Operations to Move Ones to the End

The problem gives us a binary string s, consisting only of characters '0' and '1'. We are allowed to repeatedly perform a specific operation: - Find an index i such that: - s[i] == '1' - s[i + 1] == '0' - Move that '1' to the right until it either: - reaches the end of the…

leetcodemediumstringgreedycounting
LeetCode 3276 - Select Cells in Grid With Maximum Score

The problem requires us to select cells from a 2D matrix grid such that no two selected cells are in the same row, and all selected values are unique. Our goal is to maximize the sum of these selected values.

leetcodehardarraydynamic-programmingbit-manipulationmatrixbitmask
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 252A - Little Xor

We are given a sequence of non-negative integers and we want to pick a contiguous block of elements such that when we take the bitwise XOR of everything inside that block, the result is as large as possible.

codeforcescompetitive-programmingbrute-forceimplementation
LeetCode 2039 - The Time When the Network Becomes Idle

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

leetcodemediumarraybreadth-first-searchgraph-theory
LeetCode 2875 - Minimum Size Subarray in Infinite Array

This problem gives us a finite array nums, but asks us to imagine an infinite array called infinitenums created by repeating nums forever. For example: We must find the shortest contiguous subarray in this infinite sequence whose sum is exactly equal to target.

leetcodemediumarrayhash-tablesliding-windowprefix-sum
CF 261C - Maxim and Matrix

We are given a very large range of possible values for a parameter m, and for each such value a deterministic procedure produces a matrix filled using bitwise XOR rules. The matrix has size (m + 1) by (m + 1), and the filling follows a fixed recursive or constructive pattern.

codeforcescompetitive-programmingconstructive-algorithmsdpmath
LeetCode 2990 - Loan Types

The problem requires identifying users who have taken both a "Refinance" loan and a "Mortgage" loan. The input is a table Loans containing loanid, userid, and loantype. Each row represents one loan taken by a user, and loanid is unique.

leetcodeeasydatabase
CF 425D - Sereja and Squares

We are given a set of $n$ points on a 2D plane, each with integer coordinates, and all points are distinct. The task is to count how many axis-aligned squares exist whose four corners are all points from this set.

codeforcescompetitive-programmingbinary-searchdata-structureshashing
LeetCode 2161 - Partition Array According to Given Pivot

This problem asks us to rearrange an array around a given pivot value while preserving relative ordering inside certain groups. We are given an integer array nums and an integer pivot. The goal is to reorganize the array into three consecutive sections: 1.

leetcodemediumarraytwo-pointerssimulation
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 3155 - Maximum Number of Upgradable Servers

The problem requires calculating the maximum number of servers that can be upgraded at each data center independently, given the number of servers, upgrade costs, potential revenue from selling servers, and available money.

leetcodemediumarraymathbinary-search
LeetCode 2580 - Count Ways to Group Overlapping Ranges

The problem gives us a list of integer ranges, where each range represents all integers between start and end, inclusive. We must divide all ranges into exactly two groups. Either group may be empty. The important restriction is that overlapping ranges cannot be separated.

leetcodemediumarraysorting
LeetCode 2731 - Movement of Robots

The problem gives us a list of robots positioned on an infinite number line. Each robot starts at a unique coordinate from the array nums, and each robot has an associated movement direction from the string s. A robot moves exactly one unit per second.

leetcodemediumarraybrainteasersortingprefix-sum
LeetCode 2546 - Apply Bitwise Operations to Make Strings Equal

The problem provides two binary strings, s and target, of equal length n. You are allowed to perform a specific bitwise operation on s any number of times, which involves picking two distinct indices i and j and updating s[i] to s[i] OR s[j] and s[j] to s[i] XOR s[j].

leetcodemediumstringbit-manipulation
CF 158E - Phone Talks

We are asked to schedule a day of phone calls for Mr. Jackson in a way that maximizes the longest uninterrupted segment of sleep. Each call has a specific start time and duration.

codeforcescompetitive-programming*specialdpsortings
LeetCode 3359 - Find Sorted Submatrices With Maximum Element at Most K

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

leetcodehardarraystackmatrixmonotonic-stack
LeetCode 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 2959 - Number of Possible Sets of Closing Branches

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

leetcodehardbit-manipulationgraph-theoryheap-(priority-queue)enumerationshortest-path
LeetCode 2548 - Maximum Price to Fill a Bag

The problem is asking us to maximize the total price of items placed in a bag with a fixed capacity. Each item is defined by a price and a weight, but unlike traditional knapsack problems, items can be divided proportionally, meaning we can take fractions of an item.

leetcodemediumarraygreedysorting
LeetCode 1869 - Longer Contiguous Segments of Ones than Zeros

The problem gives us a binary string s, which means the string contains only the characters '0' and '1'. We need to determine whether the longest contiguous sequence of 1s is strictly longer than the longest contiguous sequence of 0s.

leetcodeeasystring
LeetCode 2051 - The Category of Each Member in the Store

This problem asks us to classify every store member into a category based on their shopping behavior. The classification depends on how often a member makes a purchase after visiting the store. We are given three database tables: - Members contains the list of all members.

leetcodemediumdatabase
LeetCode 2252 - Dynamic Pivoting of a Table

This problem requires implementing a SQL-style pivot operation programmatically. The input is a table named Products with columns productid, store, and price, where each row represents the price of a product in a specific store.

leetcodeharddatabase
CF 238C - World Eater Brothers

We are given a world of n countries connected by n-1 directed roads. Ignoring the direction of these roads, the countries form a tree. Each brother wants to establish rule in some country and can control every country reachable via directed roads.

codeforcescompetitive-programmingdfs-and-similardpgreedytrees
LeetCode 2511 - Maximum Enemy Forts That Can Be Captured

In this problem, we are given an array called forts, where each position represents one of three possible states: - 1 means the fort belongs to us. - 0 means there is an enemy fort. - -1 means the position is empty.

leetcodeeasyarraytwo-pointers
CF 205A - Little Elephant and Rozdil

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

codeforcescompetitive-programmingbrute-forceimplementation
LeetCode 2616 - Minimize the Maximum Difference of Pairs

The problem asks us to select exactly p disjoint pairs from the array nums such that the largest difference among all chosen pairs is as small as possible.

leetcodemediumarraybinary-searchdynamic-programminggreedysorting
LeetCode 2220 - Minimum Bit Flips to Convert Number

The problem asks us to determine the minimum number of bit flips required to transform an integer start into another integer goal. A bit flip is defined as changing a single bit in the binary representation of a number from 0 to 1 or from 1 to 0.

leetcodeeasybit-manipulation
LeetCode 1988 - Find Cutoff Score for Each School

This problem asks us to compute a minimum score requirement (cutoff score) for each school such that the number of students who meet or exceed that score does not exceed the school’s capacity, while also making that number as large as possible.

leetcodemediumdatabase
LeetCode 2643 - Row With Maximum Ones

Here is the complete, detailed technical solution guide for LeetCode 2643 - Row With Maximum Ones following your exact formatting requirements. The problem presents a binary matrix mat of size m x n, where each element is either 0 or 1.

leetcodeeasyarraymatrix
CF 152D - Frames

We are given an n × m grid where some cells are painted with and the others are empty .. The picture is supposed to come from painting exactly two rectangular frames. A frame is not a filled rectangle. Only the border cells of the rectangle are painted.

codeforcescompetitive-programmingbrute-force
CF 213B - Numbers

This is a Type A, “Find all X” problem. A complete solution must do two things: First, it must show that every listed family of solutions actually satisfies the system. Second, it must prove that no other solutions exist. The proposed proof does both parts.

codeforcescompetitive-programmingcombinatoricsdp
CF 251D - Two Sets

We are given a sequence of non-negative integers and must split it into two groups. One group remains with Petya and the other is given to Masha. For each group we compute the XOR of all numbers assigned to it, and we call these values x1 and x2.

codeforcescompetitive-programmingbitmasksmath
LeetCode 2801 - Count Stepping Numbers in Range

The problem asks us to count how many integers in the inclusive range [low, high] are stepping numbers. A stepping number is defined as a number where every pair of adjacent digits differs by exactly 1.

leetcodehardstringdynamic-programming
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
LeetCode 2451 - Odd String Difference

The problem gives us an array of strings where every string has the same length. For each string, we construct a difference array by subtracting the alphabet position of consecutive characters.

leetcodeeasyarrayhash-tablestring
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 3190 - Find Minimum Operations to Make All Elements Divisible by Three

The problem gives us an integer array nums. In one operation, we are allowed to either increase or decrease any single element by exactly 1. Our goal is to make every number in the array divisible by 3, while using the smallest possible number of operations.

leetcodeeasyarraymath
LeetCode 2550 - Count Collisions of Monkeys on a Polygon

In this problem, we have a regular polygon with n vertices, and each vertex initially contains exactly one monkey. Every monkey must move simultaneously to one of its two neighboring vertices.

leetcodemediummathrecursion
LeetCode 2202 - Maximize the Topmost Element After K Moves

In this problem, we are given a pile of integers represented as an array nums, where nums[0] is the current top element of the pile. We must perform exactly k moves, and in each move we are allowed to do one of two operations: 1. Remove the current top element from the pile. 2.

leetcodemediumarraygreedy
LeetCode 1938 - Maximum Genetic Difference Query

The problem presents a rooted tree where each node is uniquely identified by an integer from 0 to n-1. This integer also represents the genetic value of the node.

leetcodehardarrayhash-tablebit-manipulationdepth-first-searchtrie
CF 414E - Mashmokh's Designed Problem

We are given a rooted tree with n vertices, where each vertex explicitly lists its children in a defined order. The tree allows three types of queries. The first type asks for the distance between two nodes in terms of the number of edges along the shortest path.

codeforcescompetitive-programmingdata-structures
LeetCode 2154 - Keep Multiplying Found Values by Two

This problem asks us to repeatedly search for a value inside an integer array and double that value whenever it is found. We begin with the integer original. If that number exists anywhere in the array nums, we multiply it by two and repeat the process using the new value.

leetcodeeasyarrayhash-tablesortingsimulation
LeetCode 2491 - Divide Players Into Teams of Equal Skill

This problem asks us to divide a given list of player skill levels into teams of exactly two players such that every team has the same total skill.

leetcodemediumarrayhash-tabletwo-pointerssorting
LeetCode 3218 - Minimum Cost for Cutting Cake I

The problem gives us an m x n rectangular cake and asks us to cut it into individual 1 x 1 pieces. We are allowed to cut along predefined horizontal and vertical lines. Each line has a fixed cost associated with it.

leetcodemediumarraytwo-pointersdynamic-programminggreedysorting
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 243C - Colorado Potato Beetle

We are working on an enormous infinite grid of unit square cells, and we can think of each cell as a “bed” in a potato field. We start in the center cell and walk according to a sequence of axis-aligned moves.

codeforcescompetitive-programmingdfs-and-similarimplementation
LeetCode 1972 - First and Last Call On the Same Day

The problem provides a table of phone call records where each row contains a caller, a recipient, and a timestamp. Each call is bidirectional in the sense that both participants are considered to have made and received the call simultaneously.

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

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

codeforcescompetitive-programminggreedyimplementation
LeetCode 2338 - Count the Number of Ideal Arrays

The problem asks us to count how many arrays of length n satisfy a divisibility condition while keeping every value within the range [1, maxValue]. An array arr is considered ideal if: 1. Every element is between 1 and maxValue. 2.

leetcodehardmathdynamic-programmingcombinatoricsnumber-theory
LeetCode 2119 - A Number After a Double Reversal

The problem asks us to determine whether a number remains unchanged after performing two digit reversals. A digit reversal means reading the digits of a number from right to left.

leetcodeeasymath
LeetCode 2597 - The Number of Beautiful Subsets

The problem asks us to count how many non-empty subsets of the array nums are considered "beautiful". A subset is beautiful if there are no two numbers inside the subset whose absolute difference equals k.

leetcodemediumarrayhash-tablemathdynamic-programmingbacktrackingsortingcombinatorics
LeetCode 2389 - Longest Subsequence With Limited Sum

This problem asks us to determine, for each query, the maximum number of elements we can select from an array nums such that their sum does not exceed a given value.

leetcodeeasyarraybinary-searchgreedysortingprefix-sum
LeetCode 3015 - Count the Number of Houses at a Certain Distance I

Here is a complete technical solution guide for LeetCode 3015 - Count the Number of Houses at a Certain Distance I, formatted according to your specifications. The problem describes a simple linear city with n houses numbered from 1 to n.

leetcodemediumbreadth-first-searchgraph-theoryprefix-sum
LeetCode 3081 - Replace Question Marks in String to Minimize Its Value

The problem gives us a string s containing lowercase English letters and the character '?'. Every '?' must be replaced with a lowercase letter so that the resulting string has the minimum possible value.

leetcodemediumhash-tablestringgreedysortingheap-(priority-queue)counting
LeetCode 2238 - Number of Times a Driver Was a Passenger

The problem provides a table Rides that records rides between drivers and passengers. Each row has a unique rideid, a driverid, and a passengerid. The task is to determine, for each driver, how many times that driver has appeared as a passenger in the table.

leetcodemediumdatabase
LeetCode 3397 - Maximum Number of Distinct Elements After Operations

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

leetcodemediumarraygreedysorting
CF 203C - Photographer

Each client describes a fixed amount of work Valera must perform: a certain number of low quality photos and a certain number of high quality photos.

codeforcescompetitive-programminggreedysortings
CF 270A - Fancy Fence

We are asked to determine whether a robot, which can only make fence corners at a fixed angle a, can construct a regular polygon. A regular polygon is defined as a closed shape with all sides and all angles equal.

codeforcescompetitive-programminggeometryimplementationmath
LeetCode 2619 - Array Prototype Last

The problem asks us to enhance all JavaScript arrays so that they have a convenient method, last(), which returns the last element of the array. If the array is empty, it should return -1.

leetcodeeasy
LeetCode 2623 - Memoize

This problem asks us to create a memoized version of a function. Memoization is a technique where you store the results of expensive function calls and return the cached result when the same inputs occur again.

leetcodemedium
LeetCode 2523 - Closest Prime Numbers in Range

The problem asks us to find two prime numbers inside a given inclusive range [left, right] such that the difference between them is as small as possible.

leetcodemediummathnumber-theory
LeetCode 2866 - Beautiful Towers II

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

leetcodemediumarraystackmonotonic-stack
LeetCode 1977 - Number of Ways to Separate Numbers

The problem asks us to determine the number of ways a string of digits, num, can be split into a sequence of positive integers that are non-decreasing and have no leading zeros.

leetcodehardstringdynamic-programmingsuffix-array
LeetCode 2694 - Event Emitter

This problem asks us to design a simplified event system similar to the one used in environments like Node.js or browser DOM events. The goal is to implement an EventEmitter class that supports two operations: 1. Subscribing callback functions to named events 2.

leetcodemedium
CF 181A - Series of Crimes

We are given a map of a city as an n × m grid, where each cell represents a district. Three of the districts have been robbed, marked by , and all other districts are empty (.).

codeforcescompetitive-programmingbrute-forcegeometryimplementation
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
LeetCode 2130 - Maximum Twin Sum of a Linked List

The problem gives us a singly linked list with an even number of nodes. For every node at index i, there is a corresponding twin node at index n - 1 - i, where n is the total number of nodes in the list. We define the twin sum as: - node[i].val + node[n - 1 - i].

leetcodemediumlinked-listtwo-pointersstack
CF 197A - Plate Game

We have a rectangular table with dimensions a × b and an unlimited supply of identical circular plates with radius r. Two players alternate placing plates on the table. Every plate must lie completely inside the rectangle, and plates may touch but cannot overlap.

codeforcescompetitive-programmingconstructive-algorithmsgamesmath
LeetCode 1928 - Minimum Cost to Reach Destination in Time

The problem asks us to find the minimum cost to travel from city 0 to city n-1 within a given time limit, maxTime, where the cost is defined by passing fees associated with each city visited. The country has n cities connected by bi-directional roads with varying travel times.

leetcodehardarraydynamic-programminggraph-theory
LeetCode 2633 - Convert Object to JSON String

The problem asks us to manually implement the behavior of JavaScript's JSON.stringify for valid JSON values, without using the built in function itself.

leetcodemedium
CF 148C - Terse princess

We need to construct an array of groom fortunes so that the princess reacts in exactly the required way. For every groom after the first one, two special situations are possible. If the current fortune is larger than every previous fortune, the princess says Oh....

codeforcescompetitive-programmingconstructive-algorithmsgreedy
LeetCode 3210 - Find the Encrypted String

The problem asks us to implement a custom string encryption algorithm. We are given a string s and an integer k. For each character in s, we need to replace it with the character that is k positions ahead in the string, in a cyclic manner.

leetcodeeasystring
LeetCode 2536 - Increment Submatrices by One

LeetCode 2536: Increment Submatrices by One (Medium)

leetcodemediumarraymatrixprefix-sum