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 easy

Factorial (iterative)

Compute n! iteratively without recursion.

loops math
+8 pts 8m
Python Basics easy

Clamp a Number to a Range

Implement a clamp function that returns a value within a specified range.

numbers conditionals comparisons
+5 pts 5m
Python Basics easy

Max of a variable-length list

Implement a function that returns the maximum value from a list of numbers without using max().

conditionals loops comparison
+10 pts 10m
Python Basics easy

Replace negatives with zero

Implement a function that replaces all negative numbers in a list with zero.

lists loops conditionals
+10 pts 10m
Python Basics easy

Minutes to Hours: Time Conversion Helper

Write a function that converts minutes into a human-readable 'Xh Ym' string, with special cases for zero and whole hours.

arithmetic formatting conditionals
+8 pts 10m
Python Basics easy

Is divisible by?

Create a function that returns True if a is divisible by b with no remainder, with a clear definition of edge cases.

division modulo conditionals
+10 pts 10m
Python Basics easy

Modulo Remainder

Implement a function that returns the remainder of a divided by b without using the modulo operator.

modulo arithmetic integers
+5 pts 5m
Python Basics easy

Digit Count

Count the number of digits in an integer using arithmetic, without string conversion.

numbers loops math
+8 pts 12m
Python Basics easy

Find Missing Number

Given a list of n distinct integers from 0..n with one missing, return the missing number.

math integers arrays
+10 pts 10m
Python Basics easy

Enumerate with start

Implement a function that mimics Python's enumerate with a custom start index.

enumerate loops tuples
+5 pts 5m
Python Basics easy

Convolve 1D signal

Implement a 1D convolution function with three modes using pure Python.

convolution arrays loops
+8 pts 12m
Python Basics easy

Guess Number Game

Simulate a number guessing game with attempts, feedback, and a win/lose result.

loops conditionals functions
+10 pts 15m
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
Python Basics easy

Broadcast Add Scalar

Add a scalar to every number in a 2D list and return a new 2D list without modifying the original.

nested-loops addition lists
+10 pts 15m
Python Basics easy

Reshape array dimensions

Implement a function that reshapes a 1D list into a 2D list with given dimensions.

reshape matrix lists
+8 pts 10m
Strings & Text easy

Title case converter

Return the string with each word capitalised.

strings split
+5 pts 5m
Strings & Text easy

Longest word in a sentence

Write a function that returns the longest word from a sentence, with first-occurrence tie-breaking.

strings parsing split
+8 pts 10m
Strings & Text easy

Replace vowels with stars

Write a function that replaces every vowel in a given string with an asterisk.

strings transformation vowels
+10 pts 10m
Strings & Text easy

Normalize quotes

Replace all typographic quote characters with straight ASCII quotes.

strings replacement unicode
+10 pts 12m
Strings & Text easy

Interleave Two Strings

Given two strings s1 and s2, return a new string that interleaves them character by character, starting with s1.

strings merging loops
+8 pts 10m
Strings & Text easy

Center a string in a width

Write a function that centers a string within a specified width by adding spaces on both sides.

strings padding formatting
+8 pts 10m
Strings & Text easy

Remove Duplicates from String

Given a string, return a new string with each character that repeats consecutively reduced to a single occurrence.

strings loop filter
+8 pts 10m
Strings & Text easy

Longest Word Finder

Write a function that extracts alphabetic words from a string and returns the longest one, with ties broken by earliest position.

strings parsing max
+10 pts 10m
Strings & Text easy

Abbreviate Name

Create a function that takes a full name and returns an abbreviated version with initials and the last name.

strings formatting split
+10 pts 15m
Strings & Text easy

Replace Spaces with Dashes

Write a function that replaces every space in a string with a dash.

strings replace manipulation
+5 pts 5m
Strings & Text easy

Compress Consecutive Chars

Write a function that compresses a string by replacing runs of identical characters with the character followed by the count.

string run-length compression
+8 pts 12m
Strings & Text easy

Index of First Occurrence

Implement a function that finds the starting index of a substring within a string, returning -1 when absent.

strings search index
+8 pts 12m
Strings & Text easy

Parse Log Line

Write a function that parses a log line and returns a dictionary with timestamp, level, and message.

string-parsing split strip
+10 pts 15m
Strings & Text easy

Replace multiple spaces

Implement a function that replaces every sequence of spaces with a single space.

strings whitespace normalization
+8 pts 10m
Strings & Text easy

Extract domain from URL

Extract the domain (hostname without port or www) from a given URL string.

url parsing strings
+8 pts 12m
Strings & Text hard

Basic Calculator III

Implement a recursive descent parser to evaluate a fully parenthesized arithmetic expression with +, -, *, / and parentheses.

parsing string expression
+45 pts 40m
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 easy

Parse URL components

Write parse_url that splits a URL into its standard components with defaults for missing parts.

url-parsing strings parsing
+8 pts 10m
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
Strings & Text easy

Decode base64 string

Write a function that decodes a base64 string to its original UTF-8 text without using the base64 module.

base64 decode strings
+8 pts 10m
Strings & Text easy

User Friendly Message

Given a raw user input, format it into a single clean sentence with proper sentence case and trimming.

strings formatting cleaning
+8 pts 12m
Lists & Arrays easy

Two Sum

Return indices (i, j) with i < j such that nums[i] + nums[j] == target.

dict complement
+18 pts 16m
Lists & Arrays medium

Maximum subarray (Kadane)

Find the contiguous subarray with the largest sum.

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

Remove duplicates (sorted)

Return a sorted list with duplicates removed.

arrays two-pointer
+10 pts 10m
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
Lists & Arrays easy

Find Missing Number 1 to n

Given a list containing n-1 distinct integers from 1 to n, find the missing number without using extra space.

arrays math search
+10 pts 10m
Lists & Arrays easy

Pad Array Edges

Write a function that pads a list with zeros on both ends.

lists slicing padding
+10 pts 10m
Lists & Arrays easy

Sort array by parity

Given a list of integers, return a new list with all evens first and odds last, preserving original relative order.

sorting arrays two-pointers
+10 pts 15m
Lists & Arrays easy

Linear Interpolation Array

Given an array with some None values, replace them by linear interpolation between the nearest known values.

arrays interpolation math
+8 pts 12m
Dicts & Sets easy

Are two lists the same multiset

Write a function that checks if two lists contain the same elements with the same multiplicities, ignoring order.

multiset dictionary counting
+10 pts 10m
Dicts & Sets easy

Group names by first letter

Given a list of names, return a dictionary mapping each first letter to all names starting with that letter in original order.

dictionaries strings grouping
+10 pts 10m
Dicts & Sets easy

Nested get with dotted path

Implement a function that safely retrieves a value from a deeply nested dictionary using a dot-separated path, returning a default if any key is missing.

dicts nested parsing
+8 pts 10m
Dicts & Sets easy

Top k keys by count

Given a dictionary mapping keys to counts, return the top k keys with the highest counts, breaking ties alphabetically.

dictionary sorting frequency
+10 pts 15m
Dicts & Sets easy

Replace keys with a mapping

Write a function that renames keys in a dictionary according to a mapping, with duplicate handling.

dicts mapping transformation
+8 pts 10m
Dicts & Sets easy

Two Sum with Dict

Implement the classic Two Sum problem: return indices of two numbers that add up to a target using a dict.

dictionary pair-sum hash-map
+10 pts 15m
Dicts & Sets easy

Sort by frequency

Sort a list by element frequency descending, with ties broken by order of first occurrence.

sorting frequency dictionaries
+10 pts 15m
Dicts & Sets easy

Pair with difference K

Count unordered index pairs with absolute difference exactly K, handling duplicates correctly.

dictionary set counting
+10 pts 15m
Dicts & Sets easy

Count Pairs with Sum

Implement a function that counts the number of distinct pairs in a list summing to a target.

dictionary pair-counting hash-map
+10 pts 15m
Dicts & Sets easy

Group by Department

Implement a function that groups a list of employee dictionaries by department, returning a dictionary keyed by department with lists of employee dictionaries.

dicts loops grouping
+8 pts 10m
Dicts & Sets easy

Pivot sales by product

Write a function that pivots sales records into a dictionary keyed by product with monthly totals.

dicts grouping aggregation
+10 pts 15m
OOP & Classes easy

Stack class

Implement a Stack class with push, pop, peek, is_empty, and size.

OOP stack data-structures
+12 pts 15m
OOP & Classes easy

Event emitter basics

Implement an EventEmitter class with subscribe/emit/unsubscribe functionality.

oop callbacks events
+10 pts 15m
OOP & Classes easy

Rectangle class

Implement a Rectangle class with properties, methods, and special methods for basic geometry and comparison.

classes magic-methods geometry
+10 pts 12m
OOP & Classes easy

Queue class (list-based)

Implement a Queue class with enqueue, dequeue, peek, is_empty, and is_full methods using a list.

queue oop list
+10 pts 15m
OOP & Classes easy

Abstract Base Class

Create an abstract Shape class and implement Rectangle and Circle subclasses with area and perimeter.

abc abstract oop
+10 pts 15m
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
OOP & Classes easy

Deck of Cards Class

Implement a Deck class representing a standard 52-card deck with shuffle, deal, and len support.

oop classes random
+10 pts 15m
OOP & Classes easy

Dataclass with slots

Implement a slotted frozen dataclass representing a 2D point with total ordering.

dataclass slots immutability
+10 pts 15m
OOP & Classes easy

Playing card class

Design a PlayingCard class with suit, rank, color, and equality/comparison magic methods.

oop classes magic-methods
+10 pts 15m
Data Structures & Algorithms easy

Count pairs with given difference

Count how many unordered pairs in a list have a given absolute difference using an efficient approach.

hash map counting arrays
+12 pts 15m
Data Structures & Algorithms easy

Previous Smaller Element

Find the nearest previous index with a smaller value for every element in an array.

arrays stack monotonic-stack
+10 pts 15m
Data Structures & Algorithms easy

Union Find Class

Implement a UnionFind class with find and union operations supporting path compression and union by size.

union-find disjoint-set data-structures
+10 pts 15m
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
Data Structures & Algorithms easy

Delete Old Records

Filter a list of records by removing those with a date older than a given cutoff date.

filtering datetime lists
+8 pts 10m
Data Structures & Algorithms easy

Argsort Indices

Implement a function that returns the indices that would sort a list of integers, with ties broken by original order.

sorting indices lists
+8 pts 10m
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 hard

Data pipeline

Implement a Pipeline class supporting pipe chaining with the | operator.

functional OOP pipeline
1
+40 pts 35m
Advanced Python easy

Default Argument Trap

Implement a function that safely accumulates items without the classic mutable default argument bug.

default-arguments mutable immutability
+8 pts 10m
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 easy

Range-like generator

Implement a custom generator that yields numbers like Python's range but with flexible bounds.

generator yield range
+8 pts 12m
Iterators & Generators easy

File Line Reader Generator

Implement a generator function that reads a file-like object and yields each non-empty line without loading the whole file into memory.

generators file-io lazy-evaluation
+10 pts 15m
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
Iterators & Generators easy

Zip Longest Fill

Create an iterator that yields lists from multiple iterables, padding with a fill value when lengths differ.

generators zip iteration
+8 pts 12m
Iterators & Generators easy

Graph DFS Generator

Implement a generator function that performs a depth-first traversal of a graph without recursion.

generators dfs graph
+8 pts 12m
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
Decorators & Context Managers easy

Context Manager Class

Implement a context manager class that measures execution time and sets duration, with None if an exception occurred.

context-manager classes timing
+8 pts 12m
Decorators & Context Managers easy

Timer Context Manager

Implement a context manager that measures execution time of a with block and stores it.

context-manager timing measurement
+10 pts 15m
Error Handling & Exceptions easy

Safe Integer from String

Implement safe_int that converts a string to an integer, returning a default value on any failure, with support for an optional base.

exceptions parsing default-value
+10 pts 15m
Error Handling & Exceptions easy

Divide with zero check

Write a function that safely divides two numbers, catching division by zero.

exceptions division error-handling
+8 pts 10m
Regular Expressions medium

Validate Email Regex

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

regex email validation
+20 pts 25m
Regular Expressions easy

Multiline anchor match

Extract lines beginning with a plain-text prefix from multiline strings using Python's re module.

regex anchors multiline
+10 pts 15m
Regular Expressions easy

Match Balanced Parentheses with Regex

Write a function that uses regular expressions to determine if parentheses are balanced and properly nested.

regex strings validation
+10 pts 15m
Math & Number Theory easy

Clamp and round to nearest ten

Clamp a number between given bounds and round the result to the nearest ten with halves away from zero.

clamping rounding math
+10 pts 12m
Math & Number Theory easy

Lucas Sequence

Implement a function to compute the n-th Lucas number using iteration or recursion with memoization.

math sequence dynamic programming
+10 pts 15m
Math & Number Theory easy

Multiply without multiply

Write a function that multiplies two integers using only addition, subtraction, and bit shifts — no * operator.

multiplication bit-manipulation arithmetic
+8 pts 12m
Math & Number Theory easy

Chinese Remainder Theorem

Solve a system of congruences with pairwise coprime moduli using the Chinese Remainder Theorem.

modular arithmetic crt coprime
+10 pts 15m
Math & Number Theory easy

Stars and Bars Count

Implement stars_and_bars_count(n, k) which returns the number of ways to put n identical items into k distinct bins, with bins allowed to be empty.

combinatorics math combinations
+10 pts 15m
Bit Manipulation easy

Missing Number XOR

Given a list of n distinct numbers from 0 to n with one missing, use XOR to find and return the missing number.

xor bitwise arrays
+10 pts 15m
Bit Manipulation easy

Isolate Rightmost Set Bit

Given an integer, return a number with only its rightmost set bit set.

bit-manipulation bitwise algorithms
+10 pts 10m
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 easy

Add without plus

Implement a function that adds two integers using only bitwise operations, no arithmetic plus or minus.

bitwise addition xor
+10 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
Bit Manipulation easy

Clear Rightmost Set Bit

Write a function clear_rightmost_set_bit that accepts a non-negative integer and returns the integer with its rightmost set bit cleared.

bitwise bit manipulation integers
+8 pts 10m
Dynamic Programming easy

House Robber

Given a list of house values, return the maximum sum you can rob without robbing two adjacent houses.

dynamic-programming arrays optimization
+10 pts 15m
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 hard

Cherry Pickup Maximum

Given a grid with cherries, find the maximum cherries you can collect using two paths from top-left to bottom-right.

dynamic-programming 2d-grid grid-walk
+40 pts 35m
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
Trees & Binary Trees easy

Range Sum BST

Return the sum of all node values in a BST that lie within a given inclusive range [low, high].

bst tree recursion
+10 pts 15m
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 easy

Cycle Detection in a Directed Graph

Use DFS with a recursion stack to detect cycles in a directed graph.

graph dfs cycle
+10 pts 15m
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 hard

Swim in Rising Water

Find the minimum time needed to swim from the top-left to the bottom-right of a grid where water level rises and you can only move to cells with elevation ≤ current time.

graph minimax priority-queue
+30 pts 20m
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 easy

Wildcard Match (Simple)

Write a function that checks whether a string matches a pattern with '*' and '?' wildcards.

wildcard recursion string
+10 pts 15m
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 hard

Remove invalid parentheses

Given a string with parentheses and letters, return all valid strings after removing the minimum number of invalid parentheses.

backtracking parentheses string
+45 pts 40m
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 hard

Remove K Digits to Form the Smallest Number

Given a non-negative integer as a string, remove exactly k digits to form the smallest possible integer without leading zeros.

greedy stack string
+45 pts 35m
Greedy Algorithms easy

Maximize units on truck

Given box types with count and units per box, maximize total units loaded onto a truck.

greedy sorting capacity
+10 pts 15m
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 easy

Longest Substring Without Repeating Characters

Implement a function that returns the length of the longest substring without repeating characters.

strings sliding-window two-pointers
+10 pts 15m
Two Pointers & Sliding Window hard

Subarrays with K different ints

Count the number of contiguous subarrays that contain exactly K distinct integers.

sliding-window two-pointers hashmap
+40 pts 40m
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
Two Pointers & Sliding Window easy

Container With Most Water

Compute the maximum area between two vertical lines in an array of heights.

two-pointers array area-calculation
+15 pts 15m
Stacks & Queues easy

Max Stack Design

Implement a MaxStack class with push, pop, top, and get_max operations.

stack design max
+10 pts 15m
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 easy

Min Heap Class

Build a MinHeap class with push, pop, peek, and size methods that maintain a valid min-heap.

heap priority-queue class
+10 pts 15m
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
Datetime & Time Calculations easy

Age in years months days

Given birth and reference dates, return age as a dictionary with years, months, days.

datetime date arithmetic age calculation
+10 pts 15m
Datetime & Time Calculations easy

Week Number ISO

Given a date, return its ISO 8601 week number (1–53) without using datetime.isocalendar().

datetime iso date
+8 pts 12m
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 easy

Generate CSV row

Implement a function that converts a list of values into a single CSV row with correct quoting and escaping.

csv escaping strings
+8 pts 12m
Data Formats & Parsing easy

Parse YAML-like dict

Parse a simple YAML-like text with indentation into a nested dictionary.

parsing yaml dictionary
+10 pts 15m
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 easy

Encode Base64 String

Write a function that encodes a UTF-8 string into a base64 string without using the base64 module.

base64 encoding strings
+8 pts 15m
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
SQL & SQLite easy

Create Table Schema

Write a function that creates a SQLite table with a given name and columns, and returns the resulting schema as a list of column definitions.

sqlite schema table
+8 pts 10m
SQL & SQLite easy

Customers Never Order

Given Customers and Orders tables, return the names of customers with no orders, sorted alphabetically, or None if all have ordered.

sql sqlite join
+10 pts 15m
Cryptography & Hashing easy

Constant Time Compare

Write a function that compares two strings without leaking length or content via timing.

constant-time security comparison
+10 pts 15m
Cryptography & Hashing easy

Password Salt Hash

Implement a function that returns a secure salted SHA-256 password hash with a deterministic format.

hashlib sha256 security
+8 pts 12m
Cryptography & Hashing easy

XOR Cipher Encode

Implement the XOR cipher: encode a string by XORing each character with a key character.

xor encryption strings
+10 pts 10m

Showing 174 challenges

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.