Practice Arena

Python Coding Challenges

Write real Python in the browser. Instant feedback. From beginner to expert.

819 challenges 506 easy 280 medium 33 hard
Python Basics medium

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.

strings sliding-window substring
+18 pts 20m
Python Basics medium

Basic Calculator

Implement a function that evaluates a simple arithmetic expression with +, -, *, / and parentheses.

calculator parsing math
+20 pts 25m
Strings & Text medium

Minimum Remove Valid Parentheses

Given a string with parentheses and letters, remove the fewest parentheses to make it valid.

strings stack validation
+20 pts 25m
Strings & Text medium

Parse key-value lines

Parse structured key-value lines into a dictionary with support for quoted values and escaped characters.

parsing strings dictionary
+20 pts 20m
Lists & Arrays medium

Maximum subarray (Kadane)

Find the contiguous subarray with the largest sum.

dp arrays kadane
+25 pts 20m
Lists & Arrays medium

Product except self

Return an array where output[i] is the product of all elements except nums[i], without using division.

arrays prefix-sum
+25 pts 20m
OOP & Classes medium

Reentrant Lock Manager

Implement a ReentrantLock class with acquire, release, locked, owner, and helper functions that test thread-safety with real threads.

threading locking reentrant
+20 pts 20m
OOP & Classes medium

Design Twitter Feed

Implement a Twitter class with postTweet, getNewsFeed, follow, and unfollow methods.

classes sorting timeline
+25 pts 30m
Data Structures & Algorithms medium

Basic Calculator II

Evaluate a basic arithmetic expression with +, -, *, / following operator precedence.

string stack arithmetic
+25 pts 30m
Data Structures & Algorithms medium

Online Stock Span

Implement StockSpanner.next(price) that returns the maximum number of consecutive days (including today) with price <= current price.

stack monotonic-stack stock-span
+20 pts 25m
Advanced Python medium

2D Vector dataclass

Implement a Vector2D dataclass with +, -, scalar *, dot product, and magnitude.

dataclass OOP math
1
+20 pts 18m
Advanced Python medium

TypeVar bounded generic

Learn to use TypeVar with bounds to write type-safe generic functions in Python.

generics typevar typing
+20 pts 15m
Advanced Python medium

Context Variable Scope

Implement a context manager that temporarily changes a global variable and restores it afterwards, even if an exception occurs.

context-manager global-scope scope
+20 pts 20m
Iterators & Generators medium

Cartesian Product Generator

Implement a generator function that yields the Cartesian product of multiple input iterables without precomputing all results.

generators cartesian product
+20 pts 25m
Decorators & Context Managers medium

Memoize with TTL

Implement a decorator that caches function results for a limited time, returning cached values within the TTL and recomputing after expiry.

decorators memoization caching
+20 pts 20m
Regular Expressions medium

Validate Email Regex

Implement a function that validates email addresses using regex with specific rules.

regex email validation
+20 pts 25m
Bit Manipulation medium

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.

bitwise range optimization
+20 pts 15m
Bit Manipulation medium

Divide using shifts

Implement division of two integers using only bit shifts and arithmetic, without using division or modulo operators.

integer division bit shifts overflow
+20 pts 20m
Dynamic Programming medium

House Robber Circular

Solve the House Robber problem with houses arranged in a circle.

dynamic-programming arrays circular
+25 pts 30m
Dynamic Programming medium

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.

dynamic-programming grid 2d-array
+25 pts 25m
Dynamic Programming medium

Unbounded Knapsack

Given item weights and values with unlimited copies, find the maximum total value that fits in a knapsack capacity.

dynamic-programming knapsack optimization
+30 pts 25m
Dynamic Programming medium

Partition Equal Subset

Determine whether a given list of positive integers can be partitioned into two subsets with equal sum.

dynamic-programming subset-sum memoization
+30 pts 25m
Dynamic Programming medium

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.

dynamic-programming optimization arrays
+20 pts 25m
Dynamic Programming medium

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.

dynamic-programming state-machine stocks
+25 pts 25m
Dynamic Programming medium

Longest Arithmetic Subsequence

Given a list of integers, return the length of the longest arithmetic subsequence (constant difference) within it.

dp subsequence hashmap
+30 pts 25m
Dynamic Programming medium

Count subsets with sum

Given a list of integers and a target sum, count how many subsets of the list sum to the target.

subset-sum dynamic-programming counting
+20 pts 25m
Trees & Binary Trees medium

Trim BST to range

Implement a function to trim a BST to only retain nodes with values in a given inclusive range.

bst recursion tree-pruning
+25 pts 25m
Graphs & Graph Algorithms medium

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.

shortest-path negative-edges graph
+30 pts 30m
Graphs & Graph Algorithms medium

Graph Coloring

Given an undirected graph, determine if it can be colored with two colors such that adjacent vertices have different colors.

graph bipartite bfs
+20 pts 20m
Graphs & Graph Algorithms medium

Course Schedule Can Finish

Given numCourses and prerequisites, return whether all courses can be finished without cyclic dependencies.

graph cycle topological
+25 pts 30m
Graphs & Graph Algorithms medium

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.

graphs shortest-path dp
+30 pts 30m
Graphs & Graph Algorithms medium

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.

bipartite graph bfs
+25 pts 25m
Graphs & Graph Algorithms medium

Android unlock patterns

Count the number of valid Android unlock patterns of a given length using a 3x3 grid with adjacency constraints.

graphs dfs backtracking
+25 pts 30m
Graphs & Graph Algorithms medium

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.

graph shortest-path dynamic-programming
+25 pts 30m
Recursion & Backtracking medium

Word Search Backtrack

Determine if a given word exists in a 2D board by tracing adjacent cells without reusing any cell.

backtracking matrix dfs
+25 pts 25m
Recursion & Backtracking medium

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.

backtracking subset-sum partition
+25 pts 25m
Greedy Algorithms medium

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.

greedy arrays optimization
+20 pts 20m
Greedy Algorithms medium

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.

greedy two-pointers sorting
+30 pts 30m
Greedy Algorithms medium

Job Sequencing with Deadlines and Profits

Given jobs with deadlines and profits, choose a subset that maximizes profit while meeting deadline constraints.

greedy sorting scheduling
+30 pts 25m
Greedy Algorithms medium

Max events attended

Given a list of events with start and end times, find the maximum number of non-overlapping events you can attend.

greedy interval-scheduling sorting
+20 pts 20m
Binary Search medium

Koko Eating Bananas

Given piles of bananas and hours, find the minimum integer eating speed Koko needs to finish all piles within H hours.

binary-search arrays search
+25 pts 30m
Binary Search medium

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.

binary-search greedy arrays
+30 pts 25m
Binary Search medium

Maximum Running Time of n Computers

Use binary search to maximize the running time for n computers with batteries.

binary-search greedy array
+30 pts 30m
Binary Search medium

Rotated Array Search II

Implement a function to search for a target in a rotated sorted array with possible duplicates.

binary-search array search
+20 pts 20m
Binary Search medium

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.

binary search 2d matrix searching
+20 pts 25m
Two Pointers & Sliding Window medium

Container With Most Water

Given an array of heights, find the maximum area between two vertical lines that can hold water.

two-pointers array maximization
+20 pts 25m
Two Pointers & Sliding Window medium

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.

sliding-window two-pointers array
+25 pts 30m
Two Pointers & Sliding Window medium

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.

sliding-window two-pointers hash-map
+25 pts 25m
Two Pointers & Sliding Window medium

Binary Subarray with Sum

Given a binary list and a goal sum, count the number of subarrays that add up to that goal.

sliding-window two-pointers subarray
+20 pts 20m
Two Pointers & Sliding Window medium

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.

sliding-window strings hash-map
+25 pts 20m
Stacks & Queues medium

Decode String Stack

Decode a compressed string with repeated substrings like '3[a2[c]]' to 'accaccacc' using a stack-based approach.

stacks string parsing
+25 pts 20m
Stacks & Queues medium

Buildings with ocean view

Given building heights, return sorted indices of buildings that have a clear view of the ocean to their right.

stack monotonic-stack arrays
+20 pts 20m
Stacks & Queues medium

Asteroid Collision

Simulate asteroid collisions with a stack and return the remaining asteroids in original order.

stack simulation arrays
+20 pts 25m
Stacks & Queues medium

Decode Nested String

Implement a function that decodes a string with nested encoding patterns.

stack string parsing
+25 pts 30m
Heaps & Priority Queues medium

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.

heap frequency counter
+20 pts 25m
Heaps & Priority Queues medium

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.

heap queue greedy
+30 pts 25m
Heaps & Priority Queues medium

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.

heap priority queue two-sum
+25 pts 30m
Heaps & Priority Queues medium

Meeting Rooms II with Heaps

Given a list of meeting intervals, compute the minimum number of rooms required using a heap-based approach.

heap intervals greedy
+25 pts 20m
Heaps & Priority Queues medium

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.

heap priority queue greedy
+25 pts 25m
Matrix & 2D Arrays medium

Count square submatrices with all ones

Count all square submatrices consisting entirely of 1s in a binary matrix.

matrix dynamic-programming counting
+25 pts 25m
Matrix & 2D Arrays medium

Largest Plus Sign

Compute the largest possible plus sign of 1s in an n x n grid with some cells set to 0.

matrix dynamic-programming simulation
+25 pts 30m
Matrix & 2D Arrays medium

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.

matrix dfs strings
+25 pts 30m
Data Formats & Parsing medium

Extract JSON-like numbers

Parse a simplified JSON-like string without using the json module and sum all numbers found in it.

json parsing numbers
+14 pts 20m
Data Formats & Parsing medium

Flatten nested JSON

Write a function that flattens nested JSON objects into a flat dictionary with dot-separated keys, handling lists and empty objects.

json recursion dictionaries
+20 pts 25m
Data Formats & Parsing medium

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.

json dict parsing
+20 pts 20m
Data Formats & Parsing medium

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.

dict toml serialization
+20 pts 25m

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

  1. Pick a category — basics, algorithms, strings, and more
  2. Open a challenge, read the statement, and edit the starter code
  3. 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.