Python practice in Data Structures & Algorithms
Browse the rooms before signing in. All rooms are free with an account. Practice does not issue certificates.
Contains Duplicate
Before the fancy stuff: can you spot a repeat in one pass? Return whether any value appears more than once.
hashing. Free with an account.
Maximum Subarray
A trader wants the best contiguous run of daily gains and losses. Return the largest sum any contiguous slice produces (Kadane's algorithm).
arrays. Free with an account.
The Single Number
Every value appears twice except one. Find the loner in linear time and constant space, the famous XOR trick.
bit-tricks. Free with an account.
Two Sum
The classic warm-up every interview opens with: find the two numbers that add up to the target and return their indices.
hashing. Free with an account.
Best Single Trade
Buy low, sell high, once. Given a price series, return the maximum profit from one buy followed by one later sell.
arrays. Free with an account.
Longest Unique Window
A network monitor wants the longest burst with no repeated packet id. Return the length of the longest substring without a repeating character.
sliding-window. Free with an account.
Move the Zeroes
A buffer needs its empty slots pushed to the end without disturbing the order of the rest. Move all zeroes to the back, keeping the non-zeroes in place.
two-pointers. Free with an account.
Valid Parentheses
A parser needs to know if the brackets balance. Use a stack to verify every opener has its matching closer in the right order.
stacks. Free with an account.
Binary Search
A sorted index needs O(log n) lookups. Implement binary search, returning the position of the target or -1 if it is absent.
binary-search. Free with an account.
Group the Anagrams
A dictionary tool clusters words that are rearrangements of each other. Return how many distinct anagram groups a word list forms.
hashing. Free with an account.
Merge Two Sorted Lists
Two sorted runs need stitching into one. Merge them in lockstep into a single sorted list, the core of merge sort.
linked-lists. Free with an account.
Search Insert Position
If the key is missing, where would it go? Return the index of the target, or the index where it should be inserted to keep the list sorted.
binary-search. Free with an account.
Count the Components
A social graph has n people and a list of friendships. Count the connected components, the separate friend circles, with union-find.
graphs. Free with an account.
Count the Islands
A satellite grid marks land as 1 and water as 0. Count the islands, the connected blobs of land joined horizontally or vertically.
graphs. Free with an account.
Kth Largest
A leaderboard needs the kth-highest score without a full sort in mind. Return the kth largest element, the canonical heap problem.
heaps. Free with an account.
Most Frequent
A trend tracker wants the single most common value, breaking ties toward the smaller one. Return it using a frequency map.
hashing. Free with an account.
Climb the Stairs
A staircase of n steps can be taken one or two at a time. Count the distinct ways to reach the top, the gateway dynamic-programming problem.
dynamic-programming. Free with an account.
Coin Change
A vending machine must make an amount with the fewest coins, or report it is impossible. Return the minimum coin count, or -1.
dynamic-programming. Free with an account.
House Robber
A burglar cannot hit two adjacent houses. Return the maximum loot from a street of house values, no two consecutive.
dynamic-programming. Free with an account.
Longest Common Subsequence
A diff tool measures how much two strings share in order. Return the length of their longest common subsequence with a DP table.
dynamic-programming. Free with an account.