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
| Title | Level | Topics | Solved | Time limit | Memory limit | Judge |
|---|---|---|---|---|---|---|
| BookshelfPartition the books in order into shelves whose widths sum to at most L, minimizing the total of each shelf's maximum height. | Medium5 | Dynamic programmingArray+2 | No attempts yet | 1s | 128 MB | Judgeable |
| SunscreenEach cow accepts an SPF interval, each bottle has an SPF value and capacity; assign bottles to maximize the number of cows covered. | Medium5 | GreedySorting+2 | No attempts yet | 1s | 128 MB | Judgeable |
| 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. | Medium5 | GreedyString+2 | No attempts yet | 1s | 128 MB | Judgeable |
| 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. | Medium5 | GreedyTwo pointers+2 | No attempts yet | 1s | 128 MB | Judgeable |
| Broken KeyboardFor each test case, find the length of the longest substring of the sentence that contains at most m distinct characters. | Medium5 | Sliding windowString+2 | No attempts yet | 1s | 128 MB | Judgeable |
| 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. | Medium5 | SortingTwo pointers+2 | No attempts yet | 1s | 128 MB | Judgeable |
| 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. | Medium5 | GreedySorting+2 | No attempts yet | 1s | 128 MB | Judgeable |
| Bin PackingPack items into identical bins holding at most two items each so that the number of bins is minimized. | Medium5 | GreedyTwo pointers+2 | No attempts yet | 1s | 128 MB | Judgeable |
| Saruman's ArmyPlace the fewest palantirs on troop positions so every troop lies within range R of one. | Medium5 | GreedySorting+1 | No attempts yet | 1s | 128 MB | Judgeable |
| 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. | Medium5 | GreedySorting+1 | No attempts yet | 1s | 128 MB | Judgeable |
| SkyscrapersFor each queried day, count maximal blocks of adjacent skyscrapers whose heights exceed the rising sea level. | Medium5 | SortingArray+1 | No attempts yet | 2s | 128 MB | Judgeable |
| The Very Dirty ChainFor each circular string, output the lexicographically smallest rotation, without reversing the chain. | Medium5 | StringTwo pointers | No attempts yet | 1s | 128 MB | Judgeable |
| IslandGiven the edge lengths of a cycle, find the maximum over all pairs of towns of the shorter of the two arc distances. | Medium5 | Two pointersPrefix sum+1 | No attempts yet | 3s | 512 MB | Judgeable |
| 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. | Medium5 | SortingBinary search+2 | No attempts yet | 1s | 128 MB | Judgeable |
| 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. | Medium5 | Sliding windowTwo pointers+1 | No attempts yet | 1s | 128 MB | Judgeable |
| The BoardFind the longest string of zeros followed by ones that appears as a subsequence of both given binary sequences. | Medium5 | GreedyTwo pointers+1 | No attempts yet | 1s | 128 MB | Judgeable |
| The CrossingPair at most two riders per shared boat within the weight limit or send each alone, and find the lowest total fare. | Medium5 | GreedySorting+1 | No attempts yet | 2s | 128 MB | Judgeable |
| Sum of Two NumbersCount the pairs of distinct given integers whose sum has the smallest absolute difference from K. | Medium5 | Two pointersSorting | No attempts yet | 1s | 128 MB | Judgeable |
| 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. | Medium5 | GreedyTwo pointers | No attempts yet | 1s | 128 MB | Judgeable |
| 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. | Medium5 | Two pointersHash map+2 | No attempts yet | 1s | 128 MB | Judgeable |
| Cow BaseballCount triples of cows in increasing position whose second gap is at least the first gap and at most twice it. | Medium5 | Two pointersSorting | No attempts yet | 1s | 128 MB | Judgeable |
| BaumkuchenSplit the circular cake into three contiguous pieces so the smallest piece is as large as possible. | Medium5 | Binary searchTwo pointers+1 | No attempts yet | 2s | 256 MB | Judgeable |
| 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. | Medium5 | Two pointersPrefix sum+1 | No attempts yet | 5s | 64 MB | Judgeable |
| Arctic Polar ExplorerWrite an APECODE program that makes a robot with two grippers sort a line of rocks by weight using only balance comparisons. | Medium5 | SortingSimulation+2 | No attempts yet | 1s | 256 MB | Judgeable |
| Diamond CollectorSort the diamond sizes and pick two disjoint groups with spread at most K to maximize the total count. | Medium5 | SortingTwo pointers | No attempts yet | 2s | 512 MB | Judgeable |
| 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. | Medium5 | Dynamic programmingArray+2 | No attempts yet | 1s | 128 MB | Judgeable |
| Birthday PresentsPick a subset of presents whose price range is below D, maximizing total satisfaction. | Medium5 | SortingSliding window+2 | No attempts yet | 2s | 512 MB | Judgeable |
| 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. | Medium5 | StringGreedy+2 | No attempts yet | 2s | 512 MB | Judgeable |
| Intervals of Unique NumbersCount pairs (i, j) where the subarray from i to j has all distinct values, with N up to 100000. | Medium5 | Two pointersSliding window+2 | No attempts yet | 1s | 32 MB | Judgeable |
| Secret PasswordGiven two length-N sequences, decide whether one is a cyclic rotation of the other. | Medium5 | String matchingArray+2 | No attempts yet | 1s | 64 MB | Judgeable |
| 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. | Medium5 | Two pointersGreedy+2 | No attempts yet | 1s | 64 MB | Judgeable |
| Weird Measurements (Medium)Count the contiguous subarrays whose consecutive differences alternate in sign, with no zero differences allowed. | Medium5 | ArrayTwo pointers+2 | No attempts yet | 2s | 512 MB | Judgeable |
| Large Weird MeasurementsCount all contiguous intervals whose consecutive differences strictly alternate in sign, with any length-1 interval counting as weird. | Medium5 | ArrayTwo pointers+2 | No attempts yet | 2s | 512 MB | Judgeable |
| Segments greater than KCount the contiguous subarrays whose sum exceeds k. | Medium5 | Two pointersPrefix sum | No attempts yet | 2s | 512 MB | Judgeable |
| RainwaterGiven stack heights across a 2D world, compute the total rainwater trapped between the blocks after heavy rain. | Medium5 | ArrayTwo pointers+2 | No attempts yet | 1s | 256 MB | Judgeable |
| 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. | Medium5 | Two pointersSorting+1 | No attempts yet | 1s | 512 MB | Judgeable |
| 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. | Medium5 | Two pointersSliding window+2 | No attempts yet | 1s | 256 MB | Judgeable |
| QueryreuQMaintain a string under append and pop-back operations, and after each operation print the number of palindromic substrings it contains. | Medium5 | StringDynamic programming+2 | No attempts yet | 1s | 1024 MB | Judgeable |
| Zigzag SequenceGiven a sequence, find the longest contiguous block in which no three consecutive terms are monotone increasing or monotone decreasing. | Medium5 | ArrayTwo pointers+2 | No attempts yet | 1s | 1024 MB | Judgeable |
| 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. | Medium5 | SortingTwo pointers+2 | No attempts yet | 2s | 512 MB | Judgeable |
| 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. | Medium5 | Sliding windowArray+2 | No attempts yet | 2s | 1024 MB | Judgeable |
| 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. | Medium5 | Sliding windowTwo pointers+2 | No attempts yet | 1s | 512 MB | Judgeable |
| 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. | Medium5 | StringTwo pointers+1 | No attempts yet | 1.5s | 512 MB | Judgeable |
| 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. | Medium5 | ArraySorting+2 | No attempts yet | 1.5s | 512 MB | Judgeable |
| 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. | Medium5 | Brute forceImplementation+2 | No attempts yet | 1s | 128 MB | Judgeable |
| 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. | Medium5 | SortingTwo pointers+1 | No attempts yet | 1s | 512 MB | Judgeable |
| 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. | Medium5 | Two pointersArray+1 | No attempts yet | 1s | 512 MB | Judgeable |
| 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. | Medium5 | GreedyString+1 | No attempts yet | 1s | 512 MB | Judgeable |
| 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. | Medium5 | Two pointersArray+2 | No attempts yet | 0.5s | 256 MB | Judgeable |
| Carpool MatchingEach passenger has a destination point and each driver accepts a closed interval of destinations; match the maximum number of passenger-driver pairs. | Medium5 | GreedySorting+2 | No attempts yet | 3s | 512 MB | Judgeable |
| Next Greater ElementFor each element of a sequence, output the nearest greater value to its right, or -1 if none exists. | Medium5 | StackArray+2 | No attempts yet | 1s | 512 MB | Judgeable |
| 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. | Medium5 | StringTwo pointers+2 | No attempts yet | 3s | 1024 MB | Judgeable |
| PalindromeFor each string, print 0 if it is a palindrome, 1 if deleting one character makes it a palindrome, or 2 otherwise. | Medium5 | StringTwo pointers+2 | No attempts yet | 1s | 512 MB | Judgeable |
| MatchesAssign N participants to rooms 1..N so that the number of participants whose passport number equals their room number is maximized. | Medium5 | GreedySorting+2 | No attempts yet | 2s | 512 MB | Judgeable |
| Black FridayGiven up to 5000 distinct item weights, decide whether 1, 2, or 3 of them sum exactly to a target C. | Medium5 | Two pointersSorting+2 | No attempts yet | 1s | 1024 MB | Judgeable |
| 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. | Medium5 | GreedyTwo pointers+2 | No attempts yet | 1s | 256 MB | Judgeable |
| 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. | Medium6 | Number theoryMath+1 | No attempts yet | 2s | 128 MB | Judgeable |
| 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. | Medium6 | Hash mapTwo pointers+1 | No attempts yet | 2s | 128 MB | Judgeable |
| 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. | Medium6 | ArraySorting+1 | No attempts yet | 2s | 128 MB | Judgeable |
| 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. | Medium6 | Binary searchPrefix sum+1 | No attempts yet | 2s | 128 MB | Judgeable |
| Two ReversalsGiven a permutation of 1..N produced by two interval reversals of the sorted sequence, find two reversal operations that restore sorted order. | Medium6 | ArrayTwo pointers+1 | No attempts yet | 1s | 128 MB | Judgeable |
| Dance PartyGiven men and women with heights and taller/shorter partner preferences, find the maximum number of mutually satisfying man-woman pairs. | Medium6 | GreedySorting+1 | No attempts yet | 1s | 128 MB | Judgeable |
| 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. | Medium6 | Binary searchPrefix sum+1 | No attempts yet | 1s | 128 MB | Judgeable |
| Defense LineGiven an array, find the maximum length of a strictly increasing run achievable after deleting a single contiguous segment (possibly empty). | Medium6 | ArrayTwo pointers+1 | No attempts yet | 3s | 128 MB | Judgeable |
| 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. | Medium6 | StringTwo pointers+2 | No attempts yet | 1s | 128 MB | Judgeable |
| Photo ShootGiven Adam's position, each person's angle around him, and a fixed camera width, find the fewest photos that cover every person. | Medium6 | SortingGreedy+2 | No attempts yet | 1s | 128 MB | Judgeable |
| 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. | Medium6 | Two pointersSorting+2 | No attempts yet | 1s | 128 MB | Judgeable |
| 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. | Medium6 | SimulationImplementation+2 | No attempts yet | 1s | 128 MB | Judgeable |
| 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. | Medium6 | GreedyTwo pointers+1 | No attempts yet | 1s | 128 MB | Judgeable |
| 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. | Medium6 | GreedyString+2 | No attempts yet | 1s | 128 MB | Judgeable |
| PalindromeGiven a string, find the minimum number of characters to insert anywhere so the string becomes a palindrome. | Medium6 | Dynamic programmingString+2 | No attempts yet | 1s | 256 MB | Judgeable |
| 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. | Medium6 | Binary searchSorting+2 | No attempts yet | 1s | 256 MB | Judgeable |
| 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. | Medium6 | ArrayPrefix sum+2 | No attempts yet | 1s | 128 MB | Judgeable |
| 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. | Medium6 | Two pointersBinary search+2 | No attempts yet | 1s | 128 MB | Judgeable |
| 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. | Medium6 | GreedyTwo pointers+2 | No attempts yet | 1s | 128 MB | Judgeable |
| 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. | Medium6 | Sliding windowTwo pointers+2 | No attempts yet | 1s | 128 MB | Judgeable |
| FlowerpotFind the minimum width interval on the x axis that captures raindrops whose heights differ by at least D. | Medium6 | Two pointersSliding window+1 | No attempts yet | 1s | 128 MB | Judgeable |
| Cow LineupFind the minimum span of x coordinates covering at least one cow of every distinct breed id. | Medium6 | SortingSliding window+2 | No attempts yet | 1s | 128 MB | Judgeable |
| Bound FoundFor multiple targets, find the contiguous subarray whose absolute sum is closest to the target, reporting that absolute sum. | Medium6 | Prefix sumSorting+2 | No attempts yet | 1s | 128 MB | Judgeable |
| Building SnowmenGiven snowball diameters, find the maximum number of triples where each triple's sizes satisfy the stacking ratio inequalities. | Medium6 | GreedySorting+2 | No attempts yet | 1s | 128 MB | Judgeable |
| 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. | Medium6 | GreedyTwo pointers+2 | No attempts yet | 1s | 128 MB | Judgeable |
| 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. | Medium6 | GreedySorting+2 | No attempts yet | 1s | 128 MB | Judgeable |
| 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. | Medium6 | GreedySorting+2 | No attempts yet | 1s | 1024 MB | Judgeable |
| 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. | Medium6 | Hash mapSorting+2 | No attempts yet | 12s | 1024 MB | Judgeable |
| 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. | Medium6 | Two pointersMath+2 | No attempts yet | 2s | 64 MB | Judgeable |
| 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. | Medium6 | Number theoryPrefix sum+2 | No attempts yet | 2s | 128 MB | Judgeable |
| CitystarFor each street, find the five house numbers whose span (max minus min plus 1) is smallest, breaking ties by the smallest house numbers. | Medium6 | SortingSliding window+2 | No attempts yet | 1s | 128 MB | Judgeable |
| 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. | Medium6 | Dynamic programmingGreedy+1 | No attempts yet | 1s | 128 MB | Judgeable |
| 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. | Medium6 | GreedyPrefix sum+1 | No attempts yet | 3s | 512 MB | Judgeable |
| 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). | Medium6 | Dynamic programmingArray+2 | No attempts yet | 1s | 128 MB | Judgeable |
| TemperatureEach day gives an interval the temperature could lie in; find the longest run of consecutive days that can be assigned non-decreasing values. | Medium6 | GreedyTwo pointers+2 | No attempts yet | 1s | 128 MB | Judgeable |
| NumberEaterCount the number of distinct value sets obtainable as the set of a contiguous subarray of the given sequence. | Medium6 | Hash mapArray+1 | No attempts yet | 1s | 128 MB | Judgeable |
| RaceFind the length-m segment of the road that minimizes total riding time under piecewise constant speed limits. | Medium6 | Sliding windowPrefix sum+1 | No attempts yet | 1s | 512 MB | Judgeable |
| 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. | Medium6 | SimulationSorting+2 | No attempts yet | 1s | 128 MB | Judgeable |
| CyclingAmong all routes from crossing 1 to crossing n, pick the one with the smallest altitude range and then the shortest length. | Medium6 | Shortest pathTwo pointers+1 | No attempts yet | 1s | 128 MB | Judgeable |
| Robert HoodGiven C points on a plane, compute the squared distance between the farthest pair of points. | Medium6 | GeometrySorting+1 | No attempts yet | 1s | 256 MB | Judgeable |
| RLE ReplacementReplace the first occurrence of RLE string B inside RLE string A with RLE string C and print the result in RLE form. | Medium6 | String matchingTwo pointers+1 | No attempts yet | 2s | 128 MB | Judgeable |
| 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. | Medium6 | Two pointersSorting+1 | No attempts yet | 1s | 256 MB | Judgeable |
| Vacuum TubesChoose two disjoint tube pairs that fit within lengths L1 and L2 so the combined length is as large as possible. | Medium6 | SortingTwo pointers+1 | No attempts yet | 1s | 256 MB | Judgeable |
| Lunch MenuCount quadruples of one soup, one main, one dessert and one drink whose prices sum to at most L. | Medium6 | SortingTwo pointers+1 | No attempts yet | 3s | 256 MB | Judgeable |