Longest Substring with K Repeating Characters
Return the length of the longest substring of a given string in which every character appears at least K times.
Basic Calculator
Implement a function that evaluates a simple arithmetic expression with +, -, *, / and parentheses.
Minimum Remove Valid Parentheses
Given a string with parentheses and letters, remove the fewest parentheses to make it valid.
Parse key-value lines
Parse structured key-value lines into a dictionary with support for quoted values and escaped characters.
Maximum subarray (Kadane)
Find the contiguous subarray with the largest sum.
Product except self
Return an array where output[i] is the product of all elements except nums[i], without using division.
Reentrant Lock Manager
Implement a ReentrantLock class with acquire, release, locked, owner, and helper functions that test thread-safety with real threads.
Design Twitter Feed
Implement a Twitter class with postTweet, getNewsFeed, follow, and unfollow methods.
Basic Calculator II
Evaluate a basic arithmetic expression with +, -, *, / following operator precedence.
Online Stock Span
Implement StockSpanner.next(price) that returns the maximum number of consecutive days (including today) with price <= current price.
2D Vector dataclass
Implement a Vector2D dataclass with +, -, scalar *, dot product, and magnitude.
TypeVar bounded generic
Learn to use TypeVar with bounds to write type-safe generic functions in Python.
Context Variable Scope
Implement a context manager that temporarily changes a global variable and restores it afterwards, even if an exception occurs.
Cartesian Product Generator
Implement a generator function that yields the Cartesian product of multiple input iterables without precomputing all results.
Memoize with TTL
Implement a decorator that caches function results for a limited time, returning cached values within the TTL and recomputing after expiry.
Validate Email Regex
Implement a function that validates email addresses using regex with specific rules.
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.
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.
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.
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.
Count subsets with sum
Given a list of integers and a target sum, count how many subsets of the list sum to the target.
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.
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.
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.
Possible bipartition
Given N people and a list of mutual dislikes, check if they can be divided into two groups with no dislike inside a group.
Android unlock patterns
Count the number of valid Android unlock patterns of a given length using a 3x3 grid with adjacency constraints.
Floyd-Warshall: All-Pairs Shortest Paths
Implement the Floyd-Warshall algorithm to find all-pairs shortest path distances in a directed graph with possibly negative weights but no negative cycles.
Word Search Backtrack
Determine if a given word exists in a 2D board by tracing adjacent cells without reusing any cell.
Partition Equal Subset Sum (Backtracking)
Write a function that uses backtracking to decide if a list of positive integers can be partitioned into two subsets with equal sum.
Candy Distribution
Compute the minimum total candies needed so that every child gets at least one and children with higher ratings than neighbors get more candies.
Bag of Tokens Score
Given tokens with values and initial power, determine the maximum score achievable by selling tokens for power or buying tokens for score.
Job Sequencing with Deadlines and Profits
Given jobs with deadlines and profits, choose a subset that maximizes profit while meeting deadline constraints.
Max events attended
Given a list of events with start and end times, find the maximum number of non-overlapping events you can attend.
Koko Eating Bananas
Given piles of bananas and hours, find the minimum integer eating speed Koko needs to finish all piles within H hours.
Capacity to Ship Packages
Given package weights and days allowed, compute the smallest ship capacity that can deliver all packages in order within the given days.
Maximum Running Time of n Computers
Use binary search to maximize the running time for n computers with batteries.
Rotated Array Search II
Implement a function to search for a target in a rotated sorted array with possible duplicates.
Search 2D Matrix
Given a sorted 2D matrix with sorted rows and first element of each row greater than last of previous, find target efficiently.
Container With Most Water
Given an array of heights, find the maximum area between two vertical lines that can hold water.
Minimum Size Subarray Sum
Given an array of positive integers, return the minimal length of a contiguous subarray with sum at least target, or 0 if none exists.
Fruit into Baskets
Given an array of integers representing fruit types, return the maximum number of fruits you can collect in a contiguous subarray with at most two distinct types.
Binary Subarray with Sum
Given a binary list and a goal sum, count the number of subarrays that add up to that goal.
Longest Substring with At Most K Distinct Characters
Given a string and an integer k, find the length of the longest substring that contains at most k distinct characters.
Decode String Stack
Decode a compressed string with repeated substrings like '3[a2[c]]' to 'accaccacc' using a stack-based approach.
Buildings with ocean view
Given building heights, return sorted indices of buildings that have a clear view of the ocean to their right.
Asteroid Collision
Simulate asteroid collisions with a stack and return the remaining asteroids in original order.
Decode Nested String
Implement a function that decodes a string with nested encoding patterns.
Top K Frequent Elements
Given a list of integers and a number k, return the k most frequent elements in descending order of frequency, with ties broken by larger value.
Task Scheduler Heap
Given a list of tasks and a cooldown, find the minimum number of CPU intervals needed to schedule all tasks without violating the cooldown.
Find K pairs with smallest sums
Given two sorted arrays and an integer k, return the k smallest pairs (u, v) with the smallest sums, sorted by sum.
Meeting Rooms II with Heaps
Given a list of meeting intervals, compute the minimum number of rooms required using a heap-based approach.
Minimum Cost to Connect Sticks
Compute the minimum total cost to connect all sticks into one stick by repeatedly combining two sticks with the smallest lengths.
Count square submatrices with all ones
Count all square submatrices consisting entirely of 1s in a binary matrix.
Largest Plus Sign
Compute the largest possible plus sign of 1s in an n x n grid with some cells set to 0.
Word Search Matrix
Given a 2D board and a word, determine if the word can be formed by sequentially adjacent cells (horizontally or vertically), without reusing cells.
Extract JSON-like numbers
Parse a simplified JSON-like string without using the json module and sum all numbers found in it.
Flatten nested JSON
Write a function that flattens nested JSON objects into a flat dictionary with dot-separated keys, handling lists and empty objects.
Unflatten JSON dict
Given a flat dictionary with keys like 'a.b.c', reconstruct the nested dictionary where each dotted segment becomes a nested level.
Serialize dict to TOML-like
Convert nested Python dicts into a simplified TOML-like string with sorted keys, type-aware formatting, and flat table sections.
Showing 66 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.