One problem, two solutions. Every input size is a round: whoever reads less fires, and on big inputs a better Big-O hits much harder. Rivals are recorded solutions; beat them on your own time.
- 01
Twin PacketEasy
Return True if any value appears twice in the list, otherwise False. In a duel every element you read is counted and compared with your rival's as the list grows.
Brute Force O(n²)Sharp O(n) - 02
Sum LockEasy
values is sorted ascending and its values are distinct. Return True if two elements add up to exactly key, otherwise False.
Brute Force O(n²)Orderly O(n log n)Sharp O(n) - 03
One PassEasy
Return the sum of all numbers in the list. Numbers may be negative.
Brute Force O(n²)Sharp O(n) - 04
Order KeeperEasy
Return True if the list is sorted in non-decreasing order, otherwise False.
Brute Force O(n²)Sharp O(n) - 05
Silver MedalEasy
The values are distinct and in no order. Return the second largest value.
Brute Force O(n²)Sharp O(n) - 06
Buy and SellEasy
values[i] is the price on day i. Return the largest profit from buying on one day and selling on a later day. Return 0 if no profit is possible.
Brute Force O(n²)Sharp O(n) - 07
The ScalesEasy
Find a position (index) where the sum of the numbers to its left equals the sum of the numbers to its right; the number at that position belongs to neither side. Return the leftmost one, or -1 if there is none. Every number is positive.
Brute Force O(n²)Sharp O(n) - 08
No TwinEasy
Return the index of the first element that appears exactly once. Return -1 if there is none.
Brute Force O(n²)Sharp O(n) - 09
Voice of the CrowdEasy
Return the value that appears most often. There is guaranteed to be a single winner.
Brute Force O(n²)Sharp O(n) - 10
Looking for a PartnerEasy
Return the indices of the two different elements that add up to key, as a list such as [3, 17]. Order does not matter and there is exactly one answer. The list is not sorted.
Orderly O(n log n)Sharp O(n) - 11
In a RowEasy
Return the length of the longest run of consecutive integers in the unsorted list, e.g. 4, 5, 6, 7 → 4. Their positions in the list do not matter.
Brute Force O(n²)Sharp O(n) - 12
Roll CallEasy
The list is sorted and contains duplicates. Return how many distinct values it has.
Brute Force O(n²)Sharp O(n) - 13
Rolling TotalEasy
Return the largest sum over all runs of key consecutive elements.
Brute Force O(n²)Sharp O(n) - 14
The Short RunEasy
All values are positive. Return the length of the shortest contiguous run whose sum is at least key. Return 0 if there is none.
Brute Force O(n²)Sharp O(n) - 15
No RepeatsEasy
Return the length of the longest contiguous run in which no value repeats.
Orderly O(n log n)Sharp O(n) - 16
From Both EndsEasy
Return True if the list reads the same forwards and backwards, otherwise False.
Brute Force O(n²)Sharp O(n) - 17
Out of OrderEasy
Return how many pairs (i, j) have i < j and values[i] > values[j].
Brute Force O(n²)Sharp O(n) - 18
Letter ScalesEasy
text has an even length. Return True if its first half is a rearrangement (anagram) of the letters of its second half, otherwise False.
Brute Force O(n²)Sharp O(n) - 19
Threshold CounterMedium
values is sorted ascending. Return how many elements are smaller than key.
Sharp O(n)Surgeon O(log n) - 20
Majority VoteMedium
One value appears in more than half of the positions. Return that value.
Brute Force O(n²)Sharp O(n) - 21
Calendar DuelMedium
Return True if none of the [start, end] meetings overlap, otherwise False. Intervals are half-open.
Brute Force O(n²)Sharp O(n) - 22
UnbrokenMedium
Return the length of the longest run of the same letter repeated side by side in text.
Orderly O(n log n)Sharp O(n) - 23
First to PassMedium
For each element, find the first larger value to its right, or -1 if there is none. Return the list of these values.
Brute Force O(n²)Sharp O(n) - 24
Peak TrackingMedium
Return the maximum of every sliding window of length key, from left to right, as a list.
Brute Force O(n²)Sharp O(n) - 25
SkylineMedium
values are the bar heights of a histogram, each bar 1 wide. Return the area of the largest rectangle that fits inside the bars.
Brute Force O(n²)Sharp O(n) - 26
Heat WaveMedium
values are daily temperatures. Return a list that says, for each day, how many days to wait until a warmer one. If no warmer day ever comes, write 0 for that day.
Orderly O(n log n)Sharp O(n) - 27
Citation RaceMedium
values[i] is how many times paper i was cited. Return the h-index: the largest h such that at least h papers have at least h citations each.
Brute Force O(n²)Sharp O(n) - 28
The GapMedium
The values are distinct. Return the largest difference between two numbers that are neighbours once the list is sorted.
Brute Force O(n²)Sharp O(n) - 29
Calendar Clean-upMedium
intervals is a list of ranges on the number line, each [start, end]. Count ranges that overlap or touch end to end as one piece. Return how many separate pieces are left once everything is merged.
Brute Force O(n²)Sharp O(n) - 30
Neck and NeckMedium
The values are distinct. Return the smallest difference between any two of them.
Brute Force O(n²)Sharp O(n) - 31
Three BucketsMedium
values contains only 0, 1 and 2. Return the list sorted in ascending order.
Brute Force O(n²)Sharp O(n) - 32
The Best StretchMedium
Return the largest sum of a contiguous, non-empty run.
Brute Force O(n²)Sharp O(n) - 33
Quiet StreetMedium
Each number is the money in a house along a street. You cannot take from two neighbouring houses. Return the most you can collect.
Brute Force O(n²)Sharp O(n) - 34
Rising ChainMedium
Return the length of the longest strictly increasing subsequence (elements keep their order).
Brute Force O(n²)Sharp O(n) - 35
The PagerMedium
Letters are written as numbers: A=1, B=2, …, Z=26. text contains only the digits 1-9. Return how many ways it can be decoded. "12" → "AB" or "L": 2; "226" → 3.
Brute Force O(n²)Sharp O(n) - 36
Count From the BackMedium
Return the val of the key-th node from the end (key = 1 is the last node). The length of the list is not given.
Brute Force O(n²)Sharp O(n) - 37
The Longest PathMedium
Return the tree's diameter: the number of edges on the longest path between any two nodes. The path does not have to pass through the root.
Orderly O(n log n)Sharp O(n) - 38
Letter SwapHard
text contains only A, B and C. Return the length of the longest contiguous part of one repeated letter you can get by changing at most key letters.
Brute Force O(n²)Sharp O(n) - 39
Rank KHard
The values are distinct. Return the key-th largest value (the 1st largest is the maximum).
Brute Force O(n²)Sharp O(n) - 40
Middle of the StreamHard
Numbers arrive one by one. After each one, append the median of everything so far (the lower one when the count is even). Return that list.
Brute Force O(n²)Sharp O(n) - 41
Fair ShareHard
Children stand in a row with ratings values. Everyone gets at least 1 candy, and a child rated higher than a neighbour gets more than that neighbour. Return the fewest candies in total.
Brute Force O(n²)Sharp O(n) - 42
Full LapHard
Stations sit on a circle. values[i] is the fuel gained at station i minus the cost of reaching the next one. Return the index of the starting station from which the tank never goes negative for a full lap, or -1 (if one exists, it is unique).
Orderly O(n log n)Sharp O(n) - 43
Get AcrossHard
You start on box 0; values[i] is the farthest you can jump forward from box i. Return True if you can reach the last box, otherwise False.
Brute Force O(n²)Sharp O(n) - 44
A Full RoomHard
You have one room and the meetings are [start, end] intervals. Return the most meetings you can hold without an overlap.
Brute Force O(n²)Sharp O(n) - 45
Few StepsHard
Same rules as the Jump Game, and the last box is always reachable. Return the fewest jumps needed to reach it.
Brute Force O(n²)Sharp O(n) - 46
Counting RoomsHard
intervals lists the meetings as [start, end]. Every meeting must take place. Return the fewest rooms needed.
Brute Force O(n²)Sharp O(n) - 47
Bit DifferenceHard
Every number is between 0 and 255 (8 bits). Return the sum of the Hamming distances (differing bits) over all pairs of numbers.
Brute Force O(n²)Sharp O(n) - 48
The Strongest PairHard
Numbers are between 0 and 1023 (10 bits). Return the largest XOR of any two of them.
Brute Force O(n²)Sharp O(n) - 49
The Missing LinkHard
values holds the numbers 0 to n in any order with one missing (n = len(values)). Return the missing number.
Brute Force O(n²)Sharp O(n) - 50
On Its OwnHard
Every number appears twice except one. Return the one that appears once.
Brute Force O(n²)Sharp O(n) - 51
The Unpaired TwoHard
Two numbers appear once and every other number appears twice. Return the two single numbers as a list (any order).
Brute Force O(n²)Sharp O(n)