Problems

Pick a problem and write your solution in the built-in editor. The judge runs it against real test cases while you watch, and the wider archive is open to read whenever you like.

Total results389 problems
TitleLevelTopicsSolvedTime limitMemory limitJudge
BookshelfPartition the books in order into shelves whose widths sum to at most L, minimizing the total of each shelf's maximum height.Medium5Dynamic programmingArray+2No attempts yet1s128 MBJudgeable
SunscreenEach cow accepts an SPF interval, each bottle has an SPF value and capacity; assign bottles to maximize the number of cows covered.Medium5GreedySorting+2No attempts yet1s128 MBJudgeable
String ConstructionRepeatedly take the leftmost or rightmost character of S and append it to T; among all such T, output the lexicographically smallest, wrapping lines at 80 characters.Medium5GreedyString+2No attempts yet1s128 MBJudgeable
String Construction 2Build the lexicographically smallest string by repeatedly taking either the first or last character of the remaining string and appending it, with ties broken by comparing inward.Medium5GreedyTwo pointers+2No attempts yet1s128 MBJudgeable
Broken KeyboardFor each test case, find the length of the longest substring of the sentence that contains at most m distinct characters.Medium5Sliding windowString+2No attempts yet1s128 MBJudgeable
CN TowerGiven angles of landmarks around a rotating restaurant that turns 360 degrees every 72 minutes, find the shortest time window covering all distinct angles.Medium5SortingTwo pointers+2No attempts yet1s128 MBJudgeable
Card Game CheaterEve knows Adam's card order and must permute her own cards to maximize the number of positions where her card beats his.Medium5GreedySorting+2No attempts yet1s128 MBJudgeable
Bin PackingPack items into identical bins holding at most two items each so that the number of bins is minimized.Medium5GreedyTwo pointers+2No attempts yet1s128 MBJudgeable
Saruman's ArmyPlace the fewest palantirs on troop positions so every troop lies within range R of one.Medium5GreedySorting+1No attempts yet1s128 MBJudgeable
Romantic DateGiven Wibowo's 26 cards, find the maximum number of rounds he can win by pairing his cards against his opponent's 26 cards in the best order.Medium5GreedySorting+1No attempts yet1s128 MBJudgeable
SkyscrapersFor each queried day, count maximal blocks of adjacent skyscrapers whose heights exceed the rising sea level.Medium5SortingArray+1No attempts yet2s128 MBJudgeable
The Very Dirty ChainFor each circular string, output the lexicographically smallest rotation, without reversing the chain.Medium5StringTwo pointersNo attempts yet1s128 MBJudgeable
IslandGiven the edge lengths of a cycle, find the maximum over all pairs of towns of the shorter of the two arc distances.Medium5Two pointersPrefix sum+1No attempts yet3s512 MBJudgeable
Apples and Apple TreesGiven positions of n trees and m apples on a line, find the minimum distance from any apple to its nearest tree.Medium5SortingBinary search+2No attempts yet1s128 MBJudgeable
Viewing TerracesIn a chain of terraces where climbing up costs height difference and descending is free, find the most distinct terraces reachable on k credits without returning to ground.Medium5Sliding windowTwo pointers+1No attempts yet1s128 MBJudgeable
The BoardFind the longest string of zeros followed by ones that appears as a subsequence of both given binary sequences.Medium5GreedyTwo pointers+1No attempts yet1s128 MBJudgeable
The CrossingPair at most two riders per shared boat within the weight limit or send each alone, and find the lowest total fare.Medium5GreedySorting+1No attempts yet2s128 MBJudgeable
Sum of Two NumbersCount the pairs of distinct given integers whose sum has the smallest absolute difference from K.Medium5Two pointersSortingNo attempts yet1s128 MBJudgeable
Colour SequenceDecide whether a target colour string appears as a subsequence of a card row when each card shows one of its two sides and jokers match any colour.Medium5GreedyTwo pointersNo attempts yet1s128 MBJudgeable
Call Me Back, Please!Read call records with start times and durations and list every pair of numbers with opposite-direction calls that fit in one 24-hour window.Medium5Two pointersHash map+2No attempts yet1s128 MBJudgeable
Cow BaseballCount triples of cows in increasing position whose second gap is at least the first gap and at most twice it.Medium5Two pointersSortingNo attempts yet1s128 MBJudgeable
BaumkuchenSplit the circular cake into three contiguous pieces so the smallest piece is as large as possible.Medium5Binary searchTwo pointers+1No attempts yet2s256 MBJudgeable
VacationFrom a start city on a line with a fixed day budget where each move or city visit costs one day, pick the contiguous block with the most attractions.Medium5Two pointersPrefix sum+1No attempts yet5s64 MBJudgeable
Arctic Polar ExplorerWrite an APECODE program that makes a robot with two grippers sort a line of rocks by weight using only balance comparisons.Medium5SortingSimulation+2No attempts yet1s256 MBJudgeable
Diamond CollectorSort the diamond sizes and pick two disjoint groups with spread at most K to maximize the total count.Medium5SortingTwo pointersNo attempts yet2s512 MBJudgeable
Roller CoasterFrom a sequence of column heights, delete columns so the survivors strictly decrease then strictly increase (either part may be empty); output the maximum number of survivors.Medium5Dynamic programmingArray+2No attempts yet1s128 MBJudgeable
Birthday PresentsPick a subset of presents whose price range is below D, maximizing total satisfaction.Medium5SortingSliding window+2No attempts yet2s512 MBJudgeable
Turning A into BGiven two equal-length uppercase strings A and B, find the minimum number of moves that bring a chosen character to the front of A so that A becomes B, or -1 if impossible.Medium5StringGreedy+2No attempts yet2s512 MBJudgeable
Intervals of Unique NumbersCount pairs (i, j) where the subarray from i to j has all distinct values, with N up to 100000.Medium5Two pointersSliding window+2No attempts yet1s32 MBJudgeable
Secret PasswordGiven two length-N sequences, decide whether one is a cyclic rotation of the other.Medium5String matchingArray+2No attempts yet1s64 MBJudgeable
Making the Array PalindromicMerge adjacent elements (each merge sums them) so the resulting array reads the same forwards and backwards, using the fewest merges. All values are positive.Medium5Two pointersGreedy+2No attempts yet1s64 MBJudgeable
Weird Measurements (Medium)Count the contiguous subarrays whose consecutive differences alternate in sign, with no zero differences allowed.Medium5ArrayTwo pointers+2No attempts yet2s512 MBJudgeable
Large Weird MeasurementsCount all contiguous intervals whose consecutive differences strictly alternate in sign, with any length-1 interval counting as weird.Medium5ArrayTwo pointers+2No attempts yet2s512 MBJudgeable
Segments greater than KCount the contiguous subarrays whose sum exceeds k.Medium5Two pointersPrefix sumNo attempts yet2s512 MBJudgeable
RainwaterGiven stack heights across a 2D world, compute the total rainwater trapped between the blocks after heavy rain.Medium5ArrayTwo pointers+2No attempts yet1s256 MBJudgeable
Mixing two solutionsGiven a sorted array of N integers, choose two different elements whose sum is closest to 0, breaking ties toward the smaller (negative) sum.Medium5Two pointersSorting+1No attempts yet1s512 MBJudgeable
Cute RyanGiven a row of N dolls labeled 1 or 2, find the length of the shortest contiguous block containing at least K dolls labeled 1.Medium5Two pointersSliding window+2No attempts yet1s256 MBJudgeable
QueryreuQMaintain a string under append and pop-back operations, and after each operation print the number of palindromic substrings it contains.Medium5StringDynamic programming+2No attempts yet1s1024 MBJudgeable
Zigzag SequenceGiven a sequence, find the longest contiguous block in which no three consecutive terms are monotone increasing or monotone decreasing.Medium5ArrayTwo pointers+2No attempts yet1s1024 MBJudgeable
Counting the closest pair sumsGiven n integers and a target v, count how many index pairs have a sum whose distance from v is as small as possible.Medium5SortingTwo pointers+2No attempts yet2s512 MBJudgeable
Martian DNAGiven a string over K symbols and minimum counts for R of them, find the length of the shortest contiguous substring meeting all the quotas, or report impossible.Medium5Sliding windowArray+2No attempts yet2s1024 MBJudgeable
Rotating SushiOn a circular belt of N sushi plates, find the maximum number of distinct kinds in any k consecutive plates, counting the coupon kind c once more if it is not already present.Medium5Sliding windowTwo pointers+2No attempts yet1s512 MBJudgeable
Longest Increasing Palindromic SubsequenceGiven up to 10^5 integers, find the longest contiguous subarray that is a palindrome whose values strictly rise from both ends toward the center.Medium5StringTwo pointers+1No attempts yet1.5s512 MBJudgeable
A Prize No One Can WinPick a largest subset of item prices such that no pair has a sum strictly greater than X, and print its size.Medium5ArraySorting+2No attempts yet1.5s512 MBJudgeable
Jake and CakeCut a row cake at the fewest boundaries so each person gets N/4 strawberries and N/4 kiwis, and output one such cutting.Medium5Brute forceImplementation+2No attempts yet1s128 MBJudgeable
Small PenaltyPick one card from each of three players so the max minus min of the chosen numbers is as small as possible, and report that range.Medium5SortingTwo pointers+1No attempts yet1s512 MBJudgeable
AchievementsGiven practice days and a budget of paid days, find the longest run of consecutive days where the number of skipped days does not exceed the budget.Medium5Two pointersArray+1No attempts yet1s512 MBJudgeable
MagnusDelete any letters from a length-N uppercase word so the kept letters contain as many disjoint subsequences "HONI" as possible, and print that maximum.Medium5GreedyString+1No attempts yet1s512 MBJudgeable
Subsequence with the Largest Maximum-Minimum DifferenceGiven a sequence, find the shortest contiguous segment whose max minus min equals the largest such difference over all segments.Medium5Two pointersArray+2No attempts yet0.5s256 MBJudgeable
Carpool MatchingEach passenger has a destination point and each driver accepts a closed interval of destinations; match the maximum number of passenger-driver pairs.Medium5GreedySorting+2No attempts yet3s512 MBJudgeable
Next Greater ElementFor each element of a sequence, output the nearest greater value to its right, or -1 if none exists.Medium5StackArray+2No attempts yet1s512 MBJudgeable
Summer TripGiven a string of event types, count contiguous substrings of length at least two whose first and last characters are distinct and each appears only once in the substring.Medium5StringTwo pointers+2No attempts yet3s1024 MBJudgeable
PalindromeFor each string, print 0 if it is a palindrome, 1 if deleting one character makes it a palindrome, or 2 otherwise.Medium5StringTwo pointers+2No attempts yet1s512 MBJudgeable
MatchesAssign N participants to rooms 1..N so that the number of participants whose passport number equals their room number is maximized.Medium5GreedySorting+2No attempts yet2s512 MBJudgeable
Black FridayGiven up to 5000 distinct item weights, decide whether 1, 2, or 3 of them sum exactly to a target C.Medium5Two pointersSorting+2No attempts yet1s1024 MBJudgeable
Riyuna Likes Sailor UniformsGiven N shirt widths and M collar widths, a collar of width c fits a shirt of width w if w/2 <= c <= 3w/4 or w <= c <= 5w/4; find the maximum number of valid shirt-collar pairs.Medium5GreedyTwo pointers+2No attempts yet1s256 MBJudgeable
Incorrect Josephus CodeGiven n and k up to 1e9, compute the sum of k mod i for i from 1 to n efficiently using divisor block decomposition.Medium6Number theoryMath+1No attempts yet2s128 MBJudgeable
Rectangles for Four FriendsGiven up to 500,000 distinct points, count axis-aligned rectangles with fixed side lengths A and B whose corners are all present in the point set.Medium6Hash mapTwo pointers+1No attempts yet2s128 MBJudgeable
Choosing Points 2Given up to 100 points and a fixed rectangle width A and height B, find the placement that covers the maximum number of points, including boundary points.Medium6ArraySorting+1No attempts yet2s128 MBJudgeable
Cutting IntervalsGiven N intervals, find cut points A and B minimizing A then B so the total overlapped length inside [A,B] equals exactly K, or output 0 0.Medium6Binary searchPrefix sum+1No attempts yet2s128 MBJudgeable
Two ReversalsGiven a permutation of 1..N produced by two interval reversals of the sorted sequence, find two reversal operations that restore sorted order.Medium6ArrayTwo pointers+1No attempts yet1s128 MBJudgeable
Dance PartyGiven men and women with heights and taller/shorter partner preferences, find the maximum number of mutually satisfying man-woman pairs.Medium6GreedySorting+1No attempts yet1s128 MBJudgeable
Interesting SequenceFor each starting index, find the maximum even-length window whose first half sum and second half sum are both at most S, using binary search and prefix sums.Medium6Binary searchPrefix sum+1No attempts yet1s128 MBJudgeable
Defense LineGiven an array, find the maximum length of a strictly increasing run achievable after deleting a single contiguous segment (possibly empty).Medium6ArrayTwo pointers+1No attempts yet3s128 MBJudgeable
Genetic FraudDecide whether two equal-length strings share an aligned substring of length at least ceil(N/2) where every pair of aligned letters differs by at most 1.Medium6StringTwo pointers+2No attempts yet1s128 MBJudgeable
Photo ShootGiven Adam's position, each person's angle around him, and a fixed camera width, find the fewest photos that cover every person.Medium6SortingGreedy+2No attempts yet1s128 MBJudgeable
Gypsy MothsGiven tree directions from a fixed camera and a fixed angular width, find the tenth-of-a-degree angle centered on the most trees, counting only trees strictly inside the view.Medium6Two pointersSorting+2No attempts yet1s128 MBJudgeable
Citizenship ApplicationGiven a residence start date, a landing date, and trips abroad, find the earliest date the 1095 qualifying days for Canadian citizenship are met.Medium6SimulationImplementation+2No attempts yet1s128 MBJudgeable
Tian Ji — The Horse RacingGiven two sets of n horse speeds, pair them one to one to maximize Tian Ji's score where a win counts 200, a loss counts -200, and a tie counts 0.Medium6GreedyTwo pointers+1No attempts yet1s128 MBJudgeable
Valid Binary StringGiven a binary string with erased positions, decide whether the missing bits can be filled so the counts of 0 and 1 are equal and no character runs three times in a row.Medium6GreedyString+2No attempts yet1s128 MBJudgeable
PalindromeGiven a string, find the minimum number of characters to insert anywhere so the string becomes a palindrome.Medium6Dynamic programmingString+2No attempts yet1s256 MBJudgeable
DartsWith up to four darts and N region scores, find the largest total not exceeding M, or 0 if every reachable total is over M.Medium6Binary searchSorting+2No attempts yet1s256 MBJudgeable
Light Bulb DecorationGiven a binary string, flip at most one contiguous range so that some contiguous alternating substring becomes as long as possible, and report that length.Medium6ArrayPrefix sum+2No attempts yet1s128 MBJudgeable
Finding SeatsGiven an R by C grid of free and taken seats, place K people on free seats so the bounding rectangle has the smallest area.Medium6Two pointersBinary search+2No attempts yet1s128 MBJudgeable
The Splitting ClubGiven distinct ages with member counts and a ratio R, partition all age groups into the fewest contiguous sections where the max count in a section is at most R times the min count.Medium6GreedyTwo pointers+2No attempts yet1s128 MBJudgeable
Cow LineupGiven a sequence of N breed IDs, remove at most K distinct breed IDs so that the longest run of equal IDs in the remaining sequence is maximized.Medium6Sliding windowTwo pointers+2No attempts yet1s128 MBJudgeable
FlowerpotFind the minimum width interval on the x axis that captures raindrops whose heights differ by at least D.Medium6Two pointersSliding window+1No attempts yet1s128 MBJudgeable
Cow LineupFind the minimum span of x coordinates covering at least one cow of every distinct breed id.Medium6SortingSliding window+2No attempts yet1s128 MBJudgeable
Bound FoundFor multiple targets, find the contiguous subarray whose absolute sum is closest to the target, reporting that absolute sum.Medium6Prefix sumSorting+2No attempts yet1s128 MBJudgeable
Building SnowmenGiven snowball diameters, find the maximum number of triples where each triple's sizes satisfy the stacking ratio inequalities.Medium6GreedySorting+2No attempts yet1s128 MBJudgeable
Snow ConesGiven the handed-out and requested flavors for a line of children, find the minimum number of simultaneous-neighbor-swap time steps until each child holds the requested flavor.Medium6GreedyTwo pointers+2No attempts yet1s128 MBJudgeable
Cleaning ShiftsCover shifts 1 through T with the fewest intervals, where each interval covers a contiguous range of shifts. Return the minimum number of intervals or -1.Medium6GreedySorting+2No attempts yet1s128 MBJudgeable
TelevisionGiven N intervals on a line, choose the fewest intervals so that every point covered by any interval is covered by a chosen one, then print that count.Medium6GreedySorting+2No attempts yet1s1024 MBJudgeable
Four Integers Summing to ZeroCount the number of index tuples (a, b, c, d) with A[a] + B[b] + C[c] + D[d] = 0, given four arrays of size n.Medium6Hash mapSorting+2No attempts yet12s1024 MBJudgeable
Graveyard DesignFind all runs of consecutive positive integers whose squares sum to a given n up to 10^14, and list each run in order of its smallest element.Medium6Two pointersMath+2No attempts yet2s64 MBJudgeable
Sum of Consecutive PrimesFor each query set of counts, find the smallest prime expressible as a sum of exactly n_i consecutive primes for every given n_i.Medium6Number theoryPrefix sum+2No attempts yet2s128 MBJudgeable
CitystarFor each street, find the five house numbers whose span (max minus min plus 1) is smallest, breaking ties by the smallest house numbers.Medium6SortingSliding window+2No attempts yet1s128 MBJudgeable
Leap FrogGiven sorted positions, Jack and Jill alternate hopping over each other within distance 10; find the minimum total jumps until one lands on the last position.Medium6Dynamic programmingGreedy+1No attempts yet1s128 MBJudgeable
A Journey to MarsFor each station on a circle, decide whether starting there with two direction choices lets Byteazar complete a full loop without running out of fuel.Medium6GreedyPrefix sum+1No attempts yet3s512 MBJudgeable
Cheap TravelsPick a sequence of hotels so consecutive stops are at most 800 km apart, minimizing total price (ties: fewest nights), and also minimizing nights (ties: lowest price).Medium6Dynamic programmingArray+2No attempts yet1s128 MBJudgeable
TemperatureEach day gives an interval the temperature could lie in; find the longest run of consecutive days that can be assigned non-decreasing values.Medium6GreedyTwo pointers+2No attempts yet1s128 MBJudgeable
NumberEaterCount the number of distinct value sets obtainable as the set of a contiguous subarray of the given sequence.Medium6Hash mapArray+1No attempts yet1s128 MBJudgeable
RaceFind the length-m segment of the road that minimizes total riding time under piecewise constant speed limits.Medium6Sliding windowPrefix sum+1No attempts yet1s512 MBJudgeable
AquariumFor each query, decide if a fish survives x days when each day fish act largest first and each eats the smallest smaller fish to gain half its mass.Medium6SimulationSorting+2No attempts yet1s128 MBJudgeable
CyclingAmong all routes from crossing 1 to crossing n, pick the one with the smallest altitude range and then the shortest length.Medium6Shortest pathTwo pointers+1No attempts yet1s128 MBJudgeable
Robert HoodGiven C points on a plane, compute the squared distance between the farthest pair of points.Medium6GeometrySorting+1No attempts yet1s256 MBJudgeable
RLE ReplacementReplace the first occurrence of RLE string B inside RLE string A with RLE string C and print the result in RLE form.Medium6String matchingTwo pointers+1No attempts yet2s128 MBJudgeable
Trapped in the HaybalesThe solver sorts bales by position, expands each gap while a neighbor is smaller than the open width, and sums the widths that never reach an end.Medium6Two pointersSorting+1No attempts yet1s256 MBJudgeable
Vacuum TubesChoose two disjoint tube pairs that fit within lengths L1 and L2 so the combined length is as large as possible.Medium6SortingTwo pointers+1No attempts yet1s256 MBJudgeable
Lunch MenuCount quadruples of one soup, one main, one dessert and one drink whose prices sum to at most L.Medium6SortingTwo pointers+1No attempts yet3s256 MBJudgeable