brain

tamnd's digital brain — notes, problems, research

43815 notes

LeetCode 3370 - Smallest Number With All Set Bits

The problem asks us to find the smallest integer x such that: 1. x = n 2. Every bit in the binary representation of x is set to 1 A number whose binary representation contains only set bits looks like this: - 1 → binary "1" - 3 → binary "11" - 7 → binary "111" - 15 →…

leetcodeeasymathbit-manipulation
CF 144D - Missile Silos

We are given a connected weighted undirected graph representing cities and roads. City s is the capital. A missile silo may be located either exactly on a city or at some interior point of a road. A position is valid if its shortest-path distance to the capital is exactly l.

codeforcescompetitive-programmingdata-structuresdfs-and-similargraphsshortest-paths
LeetCode 2949 - Count Beautiful Substrings II

The problem asks us to find the number of non-empty substrings in a given string s that satisfy two conditions simultaneously. First, the substring must have an equal number of vowels and consonants.

leetcodehardhash-tablemathstringnumber-theoryprefix-sum
LeetCode 3234 - Count the Number of Substrings With Dominant Ones

We are given a binary string s, containing only '0' and '1'. We must count how many substrings satisfy a special condition called "dominant ones".

leetcodemediumstringenumeration
LeetCode 3229 - Minimum Operations to Make Array Equal to Target

The problem gives us two arrays, nums and target, both of the same length. We are allowed to perform operations on nums until it becomes exactly equal to target.

leetcodehardarraydynamic-programmingstackgreedymonotonic-stack
LeetCode 2607 - Make K-Subarray Sums Equal

The problem asks us to transform a circular integer array so that every subarray of length k has the same sum. A circular array means the end wraps around to the beginning, so subarrays can cross the boundary of the array.

leetcodemediumarraymathgreedysortingnumber-theory
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 3363 - Find the Maximum Number of Fruits Collected

This problem asks us to maximize the total number of fruits collected by three children traversing a square grid of rooms, each with a certain number of fruits. The grid has dimensions n x n, and the fruits are given in a 2D array fruits[i][j].

leetcodehardarraydynamic-programmingmatrix
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 2171 - Removing Minimum Number of Magic Beans

The problem asks us to remove beans from bags in such a way that all non-empty bags have the same number of beans while minimizing the total number of beans removed. Each element in the input array beans represents a bag with a positive number of beans.

leetcodemediumarraygreedysortingenumerationprefix-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 2648 - Generate Fibonacci Sequence

The problem asks us to implement a generator function that yields numbers from the Fibonacci sequence. The Fibonacci sequence is defined recursively as Xn = Xn-1 + Xn-2 with the starting values X0 = 0 and X1 = 1.

leetcodeeasy
LeetCode 3055 - Top Percentile Fraud

This problem asks us to identify the top 5 percentile of insurance claims by fraud score for each state in a Fraud table. The table has three columns: policyid, state, and fraudscore.

leetcodemediumdatabase
LeetCode 2126 - Destroying Asteroids

In this problem, we are given the starting mass of a planet and a list of asteroid masses. The planet can collide with the asteroids in any order we choose.

leetcodemediumarraygreedysorting
LeetCode 2159 - Order Two Columns Independently

The problem provides a database table named Data with two integer columns: firstcol and secondcol. Each row represents a pair of numbers, and duplicate rows are allowed.

leetcodemediumdatabase
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 2779 - Maximum Beauty of an Array After Applying Operation

This problem asks us to determine the maximum "beauty" of an array after performing a set of allowed operations. Specifically, the beauty is defined as the length of the longest subsequence consisting of equal elements.

leetcodemediumarraybinary-searchsliding-windowsorting
CF 251C - Number Transformation

Codeforces 251C: Number Transformation

codeforcescompetitive-programmingdpgreedynumber-theory
CF 187B - AlgoRace

We have a complete directed graph on n cities. For every car type, we know the travel time between every ordered pair of cities. These travel times are not guaranteed to be symmetric, so going from u to v may cost something different than going from v to u.

codeforcescompetitive-programmingdpshortest-paths
LeetCode 2186 - Minimum Number of Steps to Make Two Strings Anagram II

The problem asks us to find the minimum number of steps required to make two strings, s and t, anagrams of each other. An anagram means that both strings must contain the exact same characters with the same frequency, though their order can differ.

leetcodemediumhash-tablestringcounting
LeetCode 2448 - Minimum Cost to Make Array Equal

This guide will use the weighted median optimization approach, which is the key insight behind solving this problem efficiently within the constraints. The problem gives us two arrays, nums and cost, each of length n.

leetcodehardarraybinary-searchgreedysortingprefix-sum
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
LeetCode 1919 - Leetcodify Similar Friends

This problem involves analyzing two database tables, Listens and Friendship, to determine pairs of "similar friends." In plain terms, we are asked to find pairs of users who are friends and who listened to at least three different songs on the same day.

leetcodeharddatabase
LeetCode 2244 - Minimum Rounds to Complete All Tasks

Here is a complete, detailed technical solution guide for LeetCode 2244 - Minimum Rounds to Complete All Tasks following your formatting and content requirements. The problem provides a 0-indexed array tasks, where each element represents a task's difficulty level.

leetcodemediumarrayhash-tablegreedycounting
LeetCode 2811 - Check if it is Possible to Split Array

The problem asks whether it is possible to split an input array nums into exactly n arrays of size one using a series of valid splits. Each split must take an existing array of length at least two and divide it into two good arrays.

leetcodemediumarraydynamic-programminggreedy
LeetCode 1971 - Find if Path Exists in Graph

The problem asks us to determine whether a path exists between two nodes in an undirected graph. The graph is defined by n vertices labeled from 0 to n - 1 and a list of edges, where each edge connects two distinct vertices.

leetcodeeasydepth-first-searchbreadth-first-searchunion-findgraph-theory
LeetCode 2445 - Number of Nodes With Value One

The tree in this problem is not given explicitly through an edge list. Instead, the structure is defined mathematically. Every node v has parent floor(v / 2), which creates the same structure as a binary heap.

leetcodemediumarraytreedepth-first-searchbreadth-first-searchbinary-tree
LeetCode 2844 - Minimum Operations to Make a Special Number

The problem asks us to transform a string num representing a non-negative integer into a special number by deleting as few digits as possible. A special number is defined as an integer divisible by 25.

leetcodemediummathstringgreedyenumeration
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 2236 - Root Equals Sum of Children

This problem gives us a binary tree that always contains exactly three nodes. There is one root node, one left child, and one right child. We must determine whether the value stored in the root node is equal to the sum of the values stored in its two children.

leetcodeeasytreebinary-tree
CF 243D - Cubes

We are given an n×n grid representing a city built from unit cubes stacked in towers. Each cell of the grid contains an integer indicating the height of the tower at that location.

codeforcescompetitive-programmingdata-structuresdpgeometrytwo-pointers
LeetCode 1859 - Sorting the Sentence

The problem gives us a shuffled sentence, where every word has a number appended to its end. That number represents the word's original position in the sentence, using 1-indexed ordering.

leetcodeeasystringsorting
LeetCode 2984 - Find Peak Calling Hours for Each City

The problem is asking us to analyze call records from a Calls table and determine the peak calling hour for each city. Each row in the table contains a callerid, recipientid, a timestamp (calltime), and the city where the call originated.

leetcodemediumdatabase
LeetCode 1985 - Find the Kth Largest Integer in the Array

This problem asks us to find the kth largest value among a list of integers that are represented as strings. Each element in nums is a non-negative integer encoded as a string with no leading zeros, and we are required to return the kth largest value according to numeric order…

leetcodemediumarraystringdivide-and-conquersortingheap-(priority-queue)quickselect
LeetCode 3134 - Find the Median of the Uniqueness Array

The problem defines a special array called the uniqueness array. For every possible subarray of nums, we compute how many distinct values appear inside that subarray. We then collect all of those distinct counts into a single array and sort it in non decreasing order.

leetcodehardarrayhash-tablebinary-searchsliding-window
LeetCode 2784 - Check if Array is Good

The problem defines a special type of array called a "good" array. A good array must be a permutation of: This means the array must contain: - Every integer from 1 to n - 1 exactly once - The integer n exactly twice - No other numbers - Total length equal to n + 1 The input is…

leetcodeeasyarrayhash-tablesorting
CF 448A - Rewards

We are given a fixed number of shelves and a collection of rewards split into two categories, cups and medals. Each category is further divided into three ranks, but for the placement logic those ranks do not matter beyond counting total items in each category.

codeforcescompetitive-programmingimplementation
LeetCode 1940 - Longest Common Subsequence Between Sorted Arrays

The problem asks us to find the longest common subsequence (LCS) among multiple sorted integer arrays. In simpler terms, we are given a list of arrays where each array is sorted in strictly increasing order, and we need to identify the sequence of numbers that appears in all…

leetcodemediumarrayhash-tablecounting
LeetCode 3352 - Count K-Reducible Numbers Less Than N

The problem asks us to count the number of positive integers less than n (where n is given in binary as a string s) that are k-reducible.

leetcodehardmathstringdynamic-programmingcombinatorics
LeetCode 2265 - Count Nodes Equal to Average of Subtree

This problem asks us to count how many nodes in a binary tree satisfy a specific condition: the node’s value must equal the average value of all nodes in its subtree. A subtree consists of the current node and every descendant below it.

leetcodemediumtreedepth-first-searchbinary-tree
LeetCode 2424 - Longest Uploaded Prefix

The problem asks us to design a data structure that tracks uploaded videos and continuously reports the length of the longest uploaded prefix. A prefix of uploaded videos means that every video from 1 through i has already been uploaded. The goal is to return the maximum such i.

leetcodemediumhash-tablebinary-searchunion-finddesignbinary-indexed-treesegment-treeheap-(priority-queue)ordered-set
LeetCode 2137 - Pour Water Between Buckets to Make Water Levels Equal

This problem asks us to equalize the water levels in a series of buckets while accounting for a spill loss. Each bucket initially contains some quantity of water given in an array buckets, and every time we pour water from one bucket to another, a percentage of that water…

leetcodemediumarraybinary-search
LeetCode 1936 - Add Minimum Number of Rungs

The problem gives us a ladder represented by a strictly increasing array called rungs. Each value in the array represents the height of a rung above the floor. You begin standing on the floor at height 0, and your goal is to reach the final rung.

leetcodemediumarraygreedy
CF 243B - Hydra

We are given an undirected simple graph and two small integers $h$ and $t$. We are asked to determine whether inside this graph there exists a very specific structure consisting of two special vertices connected by an edge.

codeforcescompetitive-programminggraphssortings
LeetCode 3214 - Year on Year Growth Rate

This problem asks us to compute the year-on-year, often abbreviated as YoY, growth rate of total spending for every product in the usertransactions table. Each row in the input table represents a single transaction.

leetcodeharddatabase
LeetCode 3366 - Minimum Array Sum

We are given an array nums and two different operations that can reduce the values of elements in the array. The first operation divides a number by 2 and rounds the result upward.

leetcodemediumarraydynamic-programming
CF 167B - Wizards and Huge Prize

We are asked to calculate the probability of performing well in a sequence of wizard contests, given both your chances of winning each contest and the types of prizes you may receive.

codeforcescompetitive-programmingdpmathprobabilities
LeetCode 2952 - Minimum Number of Coins to be Added

The problem asks us to determine the minimum number of coins we need to add to an existing list of coins so that every integer from 1 to a given target can be formed as the sum of some subsequence of the coins.

leetcodemediumarraygreedysorting
LeetCode 3259 - Maximum Energy Boost From Two Drinks

This problem is asking you to plan the consumption of two energy drinks over n hours to maximize the total energy boost. Each drink has a known energy contribution per hour, given by two arrays, energyDrinkA and energyDrinkB. You can drink only one energy drink per hour.

leetcodemediumarraydynamic-programming
CF 177A1 - Good Matrix Elements

We are given a square matrix of size n × n, where n is guaranteed to be an odd number. Each element of the matrix is a non-negative integer.

codeforcescompetitive-programmingimplementation
CF 424E - Colored Jenga

We are given a vertical stack of levels, each level containing three colored blocks arranged left, middle, right.

codeforcescompetitive-programmingdfs-and-similardpprobabilities
LeetCode 2136 - Earliest Possible Day of Full Bloom

The problem presents a scenario where we have n flower seeds, each of which requires two phases to bloom: a planting phase and a growth phase. Each seed i takes plantTime[i] full days to plant, which can be spread across non-consecutive days.

leetcodehardarraygreedysorting
CF 236A - Boy or Girl

We are given a username consisting only of lowercase English letters. The task is to count how many different characters appear in that username. The decision rule is simple. If the number of distinct characters is even, we print "CHAT WITH HER!".

codeforcescompetitive-programmingbrute-forceimplementationstrings
CF 306D - Polygon

We need to construct a convex polygon with exactly n vertices such that every interior angle is equal, but every side length is different. A polygon where all angles are equal is called equiangular. For a convex equiangular polygon, the direction of each edge is fixed.

codeforcescompetitive-programmingconstructive-algorithmsgeometry
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
LeetCode 2300 - Successful Pairs of Spells and Potions

The problem asks us to determine, for each spell, how many potions it can pair with to achieve a product of at least success. The arrays spells and potions represent the strengths of spells and potions, respectively.

leetcodemediumarraytwo-pointersbinary-searchsorting
LeetCode 2449 - Minimum Number of Operations to Make Arrays Similar

We are given two arrays, nums and target, of equal length. In a single operation, we choose two different indices and add 2 to one element while subtracting 2 from another element.

leetcodehardarraygreedysorting
LeetCode 2427 - Number of Common Factors

The problem gives us two positive integers, a and b, and asks us to count how many integers divide both numbers evenly. A number x is considered a common factor if: - a % x == 0 - b % x == 0 This means x divides both integers without leaving a remainder.

leetcodeeasymathenumerationnumber-theory
LeetCode 2168 - Unique Substrings With Equal Digit Frequency

The problem gives us a string s consisting only of digits from '0' to '9'. We must count how many distinct substrings satisfy a special condition: Every digit that appears in the substring must appear the same number of times. A substring is a contiguous portion of the string.

leetcodemediumhash-tablestringrolling-hashcountinghash-function
LeetCode 3093 - Longest Common Suffix Queries

The problem asks us to process a set of suffix matching queries efficiently. We are given two arrays: - wordsContainer, which contains candidate strings - wordsQuery, which contains query strings For every query string, we must find the index of the string in wordsContainer…

leetcodehardarraystringtrie
LeetCode 2279 - Maximum Bags With Full Capacity of Rocks

The problem presents n bags, each with a defined maximum capacity and a current number of rocks. The input consists of two arrays: capacity and rocks, where capacity[i] is the maximum number of rocks bag i can hold, and rocks[i] is how many rocks are currently in that bag.

leetcodemediumarraygreedysorting
LeetCode 3274 - Check if Two Chessboard Squares Have the Same Color

The problem gives us two chessboard coordinates, such as "a1" or "h8", and asks whether the two squares have the same color on a standard 8 x 8 chessboard. A chessboard alternates between black and white squares.

leetcodeeasymathstring
LeetCode 2200 - Find All K-Distant Indices in an Array

The problem requires identifying all indices in an array nums that are "k-distant" from at least one occurrence of a given value key.

leetcodeeasyarraytwo-pointers
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 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 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 2942 - Find Words Containing Character

The problem asks us to process an array of lowercase strings words and a single lowercase character x, and return all indices of the words that contain this character. In simpler terms, for each string in the array, we must check whether x appears anywhere in that string.

leetcodeeasyarraystring
LeetCode 1945 - Sum of Digits of String After Convert

This problem asks us to take a string of lowercase English letters and convert it into a numeric value, then repeatedly transform that number by summing its digits.

leetcodeeasystringsimulation
LeetCode 2697 - Lexicographically Smallest Palindrome

The problem gives us a string s consisting only of lowercase English letters. We are allowed to replace characters in the string with other lowercase letters. Our goal is to transform the string into a palindrome. A palindrome is a string that reads the same forward and backward.

leetcodeeasytwo-pointersstringgreedy
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 2664 - The Knight’s Tour

This problem asks us to construct a complete knight’s tour on an m x n chessboard. A knight’s tour is a sequence of knight moves such that every cell on the board is visited exactly once.

leetcodemediumarraybacktrackingmatrix
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 153A - A + B

We are asked to compute the sum of two integers, but the emphasis is on careful output formatting. Specifically, the input consists of two numbers, each on its own line, and we need to print their sum without any leading zeros.

codeforcescompetitive-programming*special
LeetCode 2131 - Longest Palindrome by Concatenating Two Letter Words

This problem asks us to construct the longest possible palindrome using a list of two-letter words. Each word can be used at most once, and the order of concatenation can be chosen freely.

leetcodemediumarrayhash-tablestringgreedycounting
LeetCode 2415 - Reverse Odd Levels of Binary Tree

The problem asks us to reverse the values of nodes at odd levels of a perfect binary tree. A perfect binary tree is a tree in which every parent node has exactly two children and all leaves appear at the same depth.

leetcodemediumtreedepth-first-searchbreadth-first-searchbinary-tree
LeetCode 2857 - Count Pairs of Points With Distance k

We are given a list of 2D points, where each point is represented as [x, y], and an integer k. The distance between two points is not the usual Euclidean or Manhattan distance. Instead, it is defined as: where ⊕ denotes the bitwise XOR operation.

leetcodemediumarrayhash-tablebit-manipulation
LeetCode 2622 - Cache With Time Limit

This problem asks us to implement a cache that stores key-value pairs, but unlike a normal hash map, each entry has an expiration time. A stored value remains accessible only for a limited duration measured in milliseconds.

leetcodemedium
LeetCode 3008 - Find Beautiful Indices in the Given Array II

This problem asks us to find every starting index where the substring a appears inside the string s, subject to an additional proximity condition involving another substring b. More specifically, an index i is considered beautiful if two conditions hold: 1.

leetcodehardtwo-pointersstringbinary-searchrolling-hashstring-matchinghash-function
CF 303D - Rotatable Number

We are looking for bases in which a very special cyclic behavior exists. Take a number with exactly n digits in base b. Leading zeroes are allowed, so 0011 in base 2 is a valid length-4 number.

codeforcescompetitive-programmingmathnumber-theory
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 1914 - Cyclically Rotating a Grid

The problem gives us an m x n matrix called grid, along with an integer k. Both dimensions of the matrix are guaranteed to be even numbers. The task is to rotate every layer of the matrix counter-clockwise exactly k times.

leetcodemediumarraymatrixsimulation
LeetCode 2750 - Ways to Split Array Into Good Subarrays

The problem asks us to count the number of ways we can split a given binary array nums into contiguous subarrays such that each subarray contains exactly one 1. The input is a binary array, meaning it only contains 0s and 1s.

leetcodemediumarraymathdynamic-programming
LeetCode 2450 - Number of Distinct Binary Strings After Applying Operations

We are given a binary string s of length n and an integer k. An operation consists of selecting any contiguous substring of length k and flipping every bit in that substring. A 0 becomes 1, and a 1 becomes 0. The operation may be applied any number of times, including zero times.

leetcodemediummathstring
CF 414C - Mashmokh and Reverse Operation

We are given an array of length $2^n$, where $n$ is at most 20, and a sequence of queries. Each query specifies a number $qi$, which tells us to repeatedly split the array into blocks of size $2^{qi}$, reverse each block, and then join the blocks back together.

codeforcescompetitive-programmingcombinatoricsdivide-and-conquer
CF 246B - Increase and Decrease

We have an array of integers, and we are allowed to pick two different elements and simultaneously increase one by 1 and decrease the other by 1. We can perform this operation as many times as we like.

codeforcescompetitive-programminggreedymath
LeetCode 2062 - Count Vowel Substrings of a String

The problem requires counting the number of vowel substrings in a given string word. A substring is any contiguous sequence of characters within the string.

leetcodeeasyhash-tablestring
LeetCode 2982 - Find Longest Special Substring That Occurs Thrice II

The problem asks us to find the maximum length of a special substring that appears at least three times in the given string. A substring is considered special if it consists entirely of a single repeated character.

leetcodemediumhash-tablestringbinary-searchsliding-windowcounting
CF 159D - Palindrome pairs

We are given a string of lowercase letters and need to count the number of pairs of non-overlapping palindromic substrings. Formally, we are looking for tuples (a, b, x, y) such that the substring from a to b and the substring from x to y are both palindromes and b < x.

codeforcescompetitive-programming*specialbrute-forcedpstrings
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
LeetCode 3068 - Find the Maximum Sum of Node Values

You are given a tree with n nodes. Every node has a value stored in the array nums, and every edge connects two nodes in an undirected manner.

leetcodehardarraydynamic-programminggreedybit-manipulationtreesorting
LeetCode 2994 - Friday Purchases II

The problem requires calculating the total spending by users on each Friday in November 2023, broken down by week of the month. The input is a Purchases table containing userid, purchasedate, and amountspend.

leetcodeharddatabase
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 3124 - Find Longest Calls

This problem asks us to analyze phone call records stored across two database tables and return the three longest calls for each call type, incoming and outgoing. The Contacts table stores information about people.

leetcodemediumdatabase
LeetCode 2494 - Merge Overlapping Events in the Same Hall

The problem requires us to merge overlapping events in the same hall. Each row of the HallEvents table represents an event in a particular hall with a startday and an endday. Events are considered overlapping if they share at least one day in common.

leetcodeharddatabase
LeetCode 2008 - Maximum Earnings From Taxi

The problem describes a taxi traveling along a one directional road from point 1 to point n. Along the way, passengers request rides. Each ride is represented as [start, end, tip], meaning the passenger wants to travel from start to end and will additionally pay a tip.

leetcodemediumarrayhash-tablebinary-searchdynamic-programmingsorting
LeetCode 3182 - Find Top Scoring Students

The problem gives us three relational database tables: - students, which stores each student's ID, name, and major - courses, which stores all courses along with the major they belong to - enrollments, which stores which students took which courses and the grade they received…

leetcodemediumdatabase
LeetCode 2909 - Minimum Sum of Mountain Triplets II

The problem asks us to find three indices (i, j, k) such that the middle element forms the peak of a mountain. More specifically, the indices must satisfy: - i < j < k - nums[i] < nums[j] - nums[k] < nums[j] Among all valid mountain triplets, we must return the minimum…

leetcodemediumarray
LeetCode 2038 - Remove Colored Pieces if Both Neighbors are the Same Color

This problem describes a two-player game played on a line of colored pieces. The input colors is a string representing these pieces, where each character is either 'A' or 'B'. Alice always moves first and can only remove 'A' pieces that are surrounded on both sides by 'A'.

leetcodemediummathstringgreedygame-theory
LeetCode 2585 - Number of Ways to Earn Points

This problem is essentially asking how many distinct ways we can select questions from multiple types to reach exactly a target score. Each type of question has a fixed number of questions (counti) and a fixed number of points per question (marksi).

leetcodehardarraydynamic-programming
LeetCode 2685 - Count the Number of Complete Components

This problem asks us to count how many connected components in an undirected graph are complete graphs. We are given an integer n, representing the number of vertices labeled from 0 to n - 1, and a list of undirected edges.

leetcodemediumdepth-first-searchbreadth-first-searchunion-findgraph-theory