Fibonacci(n)
Return the nth Fibonacci number efficiently.
Run-length encoding
Compress consecutive identical characters, e.g. 'aaabbc' → 'a3b2c1'.
Longest common prefix
Find the longest common prefix among a list of strings.
Integer to Roman
Convert a positive integer to its Roman numeral representation.
Zigzag string conversion
Encode a string in zigzag order across numRows rows, then read row by row.
Find all anagrams
Return all starting indices where any anagram of a given word appears as a substring.
Substring Anagrams
Return all start indices in a string where a substring of length k is an anagram of a pattern string.
Longest Palindrome Substring
Given a string s, return the longest substring that reads the same forwards and backwards.
Maximum subarray (Kadane)
Find the contiguous subarray with the largest sum.
Rotate array
Rotate a list right by k positions in place.
Flatten nested list
Yield every integer from an arbitrarily nested list, depth-first.
Merge intervals
Merge all overlapping intervals and return a sorted result.
Product except self
Return an array where output[i] is the product of all elements except nums[i], without using division.
Product of All Except Zeros Handling
Given a list of integers, return a list where each element is the product of all other elements, handling zeros correctly.
Partition around a pivot value
Implement an in-place partition of a list around a given pivot value, returning the boundary index.
Find Duplicate Number
Given a list of n+1 integers in the range 1..n, find the one integer that appears more than once.
Partition Array
Implement a function that finds a contiguous partition of a list into k groups, minimizing the maximum sum of the groups.
Two Missing Numbers
Given a list of n-2 unique integers from 1 to n, find the two missing numbers efficiently.
Three Missing Numbers
Find the three missing numbers from a shuffled list containing all but three integers from 1 to n.
Group anagrams
Group words that are anagrams of each other.
Subarray sum equals K
Count the number of contiguous subarrays whose sum equals k.
Hash map merge
Write a function that merges two dictionaries recursively, combining values and preserving structure.
Memoize decorator
Implement a @memoize decorator that caches results of a function.
Function composition
Return a function that applies f after g: compose(f, g)(x) == f(g(x)).
Linked list reversal
Implement a singly linked list and a function to reverse it in place.
Matrix addition operator
Implement a Matrix class that supports + and * operators.
Complex Number Class
Implement a Complex class supporting addition, subtraction, multiplication, division, equality, and string formatting.
Comparable mixin
Create a Comparable mixin that auto-generates all rich comparison operators from a single __lt__ method.
Class Method Factory
Create a class method factory that dynamically adds methods to a class based on a mapping of names to behaviors.
Reentrant Lock Manager
Implement a ReentrantLock class with acquire, release, locked, owner, and helper functions that test thread-safety with real threads.
Quicksort
Implement quicksort and return a sorted list.
BFS level-order traversal
Return the level-order traversal of a binary tree as a list of lists.
Coin change (DP)
Find the minimum number of coins to make exactly the target amount.
Graph DFS
Return all nodes reachable from a start node via DFS.
Count inversions lite
Implement a function that counts inversions in a list of numbers efficiently.
Find Peak Element
Implement a function that returns the index of any peak element in an integer array.
Longest Consecutive Sequence
Given an unsorted list of integers, find the length of the longest consecutive elements sequence in O(n) time.
Merge Sort
Implement merge_sort(numbers) that returns a sorted copy of the input list using the merge sort algorithm.
Heap Sort Implementation
Implement the heap sort algorithm to sort a list of comparable elements in non-decreasing order.
Radix Sort
Implement LSD radix sort to sort a list of non-negative integers in ascending order.
Bucket Sort
Implement bucket sort to sort a list of floating-point numbers in the range [0,1).
Decode Ways
Count the number of ways to decode a numeric string into letters using the mapping A=1 to Z=26.
Path Sum II All Paths
Return all root-to-leaf paths where the sum of node values equals a target.
Redundant Connection
Given a list of edges forming a tree plus one extra edge, return the edge that appears last in the input and creates a cycle.
Reconstruct Itinerary
Given a list of airline tickets, reconstruct the itinerary in order using each ticket exactly once, choosing the lexicographically smallest path when multiple options exist.
Shortest Path in Binary Matrix
Implement BFS to find the shortest path length from (0,0) to (n-1,n-1) in an n x n binary matrix, moving through 0 cells in 8 directions.
Context manager timer
Implement a Timer context manager that records elapsed seconds.
Retry decorator
Implement @retry(times=3) that retries a function on exception.
2D Vector dataclass
Implement a Vector2D dataclass with +, -, scalar *, dot product, and magnitude.
Prime Sieve Generator
Implement a generator function that yields prime numbers from 2 up to a specified limit, using an efficient sieve approach.
Memoize with TTL
Implement a decorator that caches function results for a limited time, returning cached values within the TTL and recomputing after expiry.
LRU Memoize
Implement an LRU memoization decorator that caches results for a fixed number of arguments.
Cached Property Manual
Implement a decorator that turns a method into a lazy cached attribute per instance.
Rate Limit Decorator
Implement a decorator that enforces a maximum number of calls per second for any function.
Cache result decorator
Create a decorator that stores results of function calls keyed by positional arguments.
Profile time decorator
Create a decorator that tracks how many times a function is called and its cumulative execution time.
Temporary directory manager
Implement a context manager that creates a temporary directory and automatically removes it even on errors.
Validate Email Regex
Implement a function that validates email addresses using regex with specific rules.
Match Credit Card Pattern
Write a function that validates a credit card number string against a set of formatting rules.
Smith Number Check
Write a function to check if a number is a Smith number by comparing digit sums of the number and its prime factorization.
Bitwise AND of a Range
Given a range [a, b], return the bitwise AND of all integers in that inclusive range without iterating over all numbers.
Divide using shifts
Implement division of two integers using only bit shifts and arithmetic, without using division or modulo operators.
Bit Mask Permissions
Implement helper functions to compose bit masks and check permission bits using bitwise operators.
Levenshtein Distance
Implement the classic Levenshtein distance algorithm to measure string similarity.
Kadane Variant: Maximum Product Subarray
Implement max_product_subarray(nums) that returns the maximum product of any contiguous subarray.
Max Profit from Selling Twice
Compute the maximum profit that can be achieved by completing at most two buy-sell transactions on a given price array.
Bell number
Implement a function to compute the Bell number B(n) using dynamic programming.
House Robber Circular
Solve the House Robber problem with houses arranged in a circle.
Unique Paths with Obstacles
Given a 2D grid with obstacles, count the unique paths from top-left to bottom-right moving only down or right.
Maximal square
Given a 2D binary matrix of 0s and 1s, compute the area of the largest square containing only 1s.
Longest Common Subsequence
Given two strings, compute the length of the longest subsequence common to both.
Longest Palindromic Subsequence
Compute the length of the longest palindromic subsequence in a given string.
Edit Distance (Levenshtein Distance)
Implement the classic edit distance algorithm to find the minimum number of single-character edits required to transform one string into another.
0/1 Knapsack
Implement the classic 0/1 Knapsack dynamic programming solution to maximize value under a weight capacity.
Unbounded Knapsack
Given item weights and values with unlimited copies, find the maximum total value that fits in a knapsack capacity.
Partition Equal Subset
Determine whether a given list of positive integers can be partitioned into two subsets with equal sum.
Target Sum Subsets
Write a function that counts the number of subsets of a list of positive integers that sum exactly to a target.
Coin Change Minimum
Given coin denominations and a target amount, compute the minimum number of coins needed or -1 if impossible.
Coin Change Ways
Count the number of distinct combinations of coins that sum to a target amount.
Perfect Squares Sum
Given a positive integer n, return the least number of perfect squares (e.g., 1, 4, 9, 16, ...) that sum to n.
Integer Break Product
Given a positive integer n, break it into at least two positive integers that sum to n and maximize their product.
Word Break DP
Implement a function to check if a string can be segmented into space-separated dictionary words.
Paint House Colors
Given a cost matrix, compute the minimum total cost to paint all houses with no two adjacent houses having the same color.
Buy Sell Stock with Cooldown (DP)
Given daily stock prices, compute the maximum profit you can achieve if you must wait one day after selling before buying again.
Longest Arithmetic Subsequence
Given a list of integers, return the length of the longest arithmetic subsequence (constant difference) within it.
Lowest Common Ancestor in a Binary Tree
Implement a function to find the lowest common ancestor (LCA) of two nodes in a binary tree.
Sum Root to Leaf Numbers
Given the root of a binary tree, compute the total sum of all root-to-leaf numbers.
Binary tree left side view
Given a binary tree, return the leftmost node's value at each depth, from top to bottom.
Vertical Order Traversal
Compute the vertical order traversal of a binary tree, grouping nodes by column and row.
Delete Node in BST
Implement a function that deletes a key from a binary search tree and returns the new root.
Trim BST to range
Implement a function to trim a BST to only retain nodes with values in a given inclusive range.
Bellman-Ford Algorithm
Implement the Bellman-Ford algorithm to compute shortest distances from a source in a directed weighted graph with up to 100 vertices and negative edges.
A* Pathfinding Heuristic
Implement A* search on a 2D grid to find the shortest path length between two cells.
Articulation Points
Implement a function that returns the articulation points of an undirected graph.
Bridges in Graph
Implement a function that returns all bridges in an undirected graph.
Hamiltonian Path Check
Implement a function that checks whether an undirected graph has a Hamiltonian path using DFS and backtracking.
Bipartite Graph Check
Implement a function to check if an undirected graph is bipartite using graph coloring.
Graph Coloring
Given an undirected graph, determine if it can be colored with two colors such that adjacent vertices have different colors.
Course Schedule Can Finish
Given numCourses and prerequisites, return whether all courses can be finished without cyclic dependencies.
Alien Dictionary Order
Given a sorted list of words in an alien language, derive the order of its unique letters.
Graph Valid Tree
Determine if n nodes and an edge list form a valid tree (connected and acyclic).
All Paths from Source to Target
Given a directed acyclic graph, return all paths from node 0 to the last node.
Network Delay Time
Given a directed weighted graph and a starting node, find the minimum time for a signal to reach all nodes, or -1 if unreachable.
Cheapest Flights Within K Stops
Implement a function to compute the cheapest flight price from source to destination with at most K stops in a directed weighted graph.
Combination Generator
Write a recursive function that returns all combinations of length k from a list of distinct integers.
Search in Rotated Array
Implement an efficient search in a rotated sorted array using modified binary search.
Interpolation Search
Implement interpolation search in Python on a sorted list of integers.
Ternary Search
Implement ternary search to locate the maximum of a discrete unimodal function.
Container With Most Water
Given an array of heights, find the maximum area between two vertical lines that can hold water.
Sort Colors (Dutch National Flag)
Implement the Dutch National Flag algorithm to sort an array of 0, 1, 2 in one pass.
Character Replacement Window
Given a string and a number k, find the length of the longest substring that can be made uniform by replacing at most k characters.
Permutation in String
Determine if any permutation of a shorter string appears as a contiguous substring in a longer string using an efficient sliding window.
Count Nice Subarrays
Given an array of integers, count the number of contiguous subarrays that contain exactly k odd numbers.
Top K Frequent Elements
Given an integer array and a number k, return the k most frequent elements using a heap-based approach.
Spiral Matrix Order
Given a 2D matrix, return all elements in clockwise spiral order starting from the top-left.
Number of Islands
Given a 2D grid of '1' (land) and '0' (water), count the number of islands surrounded by water.
Max Area of Island
Given a 2D grid of 0s and 1s, find the maximum area of a connected group of 1s.
01 Matrix Nearest Zero
Given a binary matrix, return a matrix of the same shape where each cell contains the Manhattan distance to the nearest 0.
Rotting Oranges Time
Given a grid of fresh, rotten, and empty cells, compute the minimum minutes until all fresh oranges rot, or -1 if some are unreachable.
Extract JSON-like numbers
Parse a simplified JSON-like string without using the json module and sum all numbers found in it.
Showing 120 challenges · medium
Guide: free Python coding challenges
Practice Python by solving problems
PythonSkillset challenges are hands-on coding exercises from beginner to advanced. Open a challenge, read the problem, write Python in the split-pane editor, and run tests with Pyodide — no install required.
How to use the arena
- Pick a category — basics, algorithms, strings, and more
- Open a challenge, read the statement, and edit the starter code
- Run tests, fix failures, then try a related quiz or tutorial lesson
Challenges vs tutorials and quizzes
Challenges test what you can build under constraints. For guided teaching, use our Python tutorials. For quick checks, try quizzes or copy snippets from code samples.