Practice Arena

Python Coding Challenges

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

467 challenges 330 easy 120 medium 17 hard
Python Basics easy

Compound interest

Return the future balance after compound interest, rounded to two decimals.

math functions finance
+12 pts 12m
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

Leap Year Checker

Implement a function that decides whether a year is a leap year according to the standard Gregorian rules.

boolean conditionals date
+5 pts 5m
Python Basics easy

Grade from Score

Write a function that maps a numeric score to its letter grade using standard grading thresholds.

conditionals functions integers
+8 pts 10m
Python Basics easy

Min of three numbers

Write a function that returns the minimum of three integers.

min comparison function
+5 pts 5m
Python Basics easy

Integer division and remainder

Write a function that performs integer division and returns both quotient and remainder.

operators division remainder
+8 pts 10m
Python Basics easy

Count down from n

Implement a function that returns a list from n down to 1.

loops range lists
+5 pts 5m
Python Basics easy

Sum numbers from 1 to n

Implement a function that computes the sum of all integers from 1 to n.

sum loop arithmetic
+5 pts 5m
Python Basics easy

Sign of a Number

Write a function that returns the sign of a number as a string.

conditionals numbers comparison
+5 pts 5m
Python Basics easy

Is a multiple of both

Write a function that returns True if a number is divisible by both of two given divisors.

modulo boolean function
+5 pts 5m
Python Basics easy

Boolean from comparison chain

Implement a function that evaluates a chain of comparisons and returns the boolean result.

comparison booleans evaluation
+8 pts 10m
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

Classify triangle by sides

Write a function that classifies a triangle based on three side lengths.

conditionals geometry validation
+8 pts 10m
Python Basics easy

Between inclusive

Write a function that returns True if a number is between two given bounds, inclusive of the bounds.

comparison conditionals boundaries
+8 pts 10m
Python Basics easy

Last Occurrence of a Value

Implement a function that returns the last index of a given value in a list, or -1 if it's not present.

lists search indexing
+10 pts 15m
Python Basics easy

Cycle a List Once

Implement a function that rotates a list right by one position.

lists rotation indexing
+5 pts 5m
Python Basics easy

Boolean Mask Filter

Write a function that filters a list based on a boolean mask and returns the selected elements.

filter boolean lists
+10 pts 15m
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

Set symmetric difference

Write a function that returns the elements found in exactly one of two sets, sorted ascending.

sets symmetric-difference sorting
+10 pts 15m
Python Basics easy

Swap Two Values

Implement a Python function that swaps two given values and returns them in swapped order.

variables assignment swap
+5 pts 5m
Python Basics easy

Hello, name!

Implement a function that returns a personalized greeting for a given name.

strings function formatting
+5 pts 5m
Python Basics easy

Leap Year Checker

Implement a function that returns True if a year is a leap year according to the Gregorian calendar rules.

conditionals boolean modulo
+10 pts 10m
Python Basics easy

Grade Calculator

Implement a function that converts a numeric score to a letter grade using a standard scale.

conditionals functions basic-syntax
+8 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

Simple Interest Calculator

Implement a function that calculates simple interest given principal, annual rate, and time in years.

arithmetic floats basics
+5 pts 5m
Python Basics easy

Tip Calculator

Write a function that calculates the total bill after adding a given tip percentage.

arithmetic rounding basics
+8 pts 10m
Python Basics easy

Absolute Difference

Implement a function that returns the absolute difference between two numbers.

absolute value arithmetic function
+5 pts 5m
Python Basics easy

Max of three numbers

Implement a function that returns the maximum of three numbers using comparisons.

conditionals comparison numbers
+10 pts 10m
Python Basics easy

Sign of a number

Write a function sign_of_number that returns -1 for negatives, 0 for zero, and 1 for positives.

conditionals numbers comparison
+5 pts 5m
Python Basics easy

Countdown printer

Implement a function that prints a countdown from a given number down to 1, then returns 'Go!'.

loops conditionals function-definition
+5 pts 5m
Python Basics easy

Sum from 1 to n

Write a function that returns the sum of all integers from 1 to n (inclusive).

math arithmetic sum
+5 pts 5m
Python Basics easy

Average of a list

Write a function that computes the average of a list of numbers, handling empty lists by returning 0.

average list statistics
+5 pts 5m
Python Basics easy

Find Minimum Value

Write a function that returns the minimum integer from a given list.

min list loop
+10 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

Round to nearest ten

Write a function that rounds any integer to the nearest multiple of ten.

arithmetic rounding integers
+8 pts 10m
Python Basics easy

Fahrenheit to Celsius

Implement a function that converts degrees Fahrenheit to degrees Celsius.

temperature arithmetic conversion
+5 pts 5m
Python Basics easy

Speed Converter

Write a function to convert speeds between kilometers per hour and meters per second.

arithmetic conversion function
+5 pts 5m
Python Basics easy

Area of Rectangle

Write a function that returns the area of a rectangle given its width and height.

arithmetic function numbers
+5 pts 5m
Python Basics easy

Circle Circumference Calculator

Implement a function that computes the circumference of a circle from its radius using the formula 2πr.

math function basics
+10 pts 10m
Python Basics easy

Volume of Cube

Write a Python function that returns the volume of a cube given its side length.

arithmetic return function
+5 pts 5m
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

Print Pyramid Pattern

Implement a function that returns a centered asterisk pyramid as a list of strings.

loops strings pattern-printing
+10 pts 15m
Python Basics easy

Last Digit Extractor

Write a function that returns the last digit of a non-negative integer using the modulo operator.

integers modulo arithmetic
+5 pts 5m
Python Basics easy

Count word occurrences

Write a function that takes a sentence and returns a dictionary of word counts.

strings counting dictionaries
+10 pts 15m
Python Basics easy

Map, Filter, Reduce

Implement three functions using map, filter, and reduce to manipulate a list of integers.

map filter reduce
+10 pts 15m
Python Basics easy

Variadic Sum Function

Implement a variadic function that sums an arbitrary number of numeric arguments.

functions args sum
+10 pts 10m
Python Basics easy

Linear Search Implementation

Implement a linear search function that returns the index of the first occurrence of a target in a list, or -1 if not found.

linear-search list index
+10 pts 15m
Python Basics easy

Garbage Collection Hint

Write a function that predicts when an object is garbage collected based on reference counting.

garbage-collection reference-counting object-lifecycle
+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

Palindromic Number Check

Write a function to check if a given integer is a palindrome.

numbers strings conditionals
+10 pts 10m
Python Basics easy

Hexagonal Number

Write a function to check if a positive integer is a hexagonal number.

math loops conditionals
+10 pts 15m
Python Basics easy

Count trailing zeros

Write a function that counts the number of trailing zeros in the decimal representation of a positive integer.

loops integers basics
+5 pts 5m
Python Basics easy

Count Leading Zeros

Write a function that returns the number of leading zeros in a list of integers.

lists iteration counting
+8 pts 8m
Strings & Text easy

Strip and Collapse Whitespace

Write a function that strips leading/trailing whitespace and collapses inner runs of whitespace to single spaces.

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

Snake case to camel case

Implement a function that converts snake_case strings to camelCase.

strings case-conversion text-processing
+10 pts 10m
Strings & Text easy

Camel case to snake case

Write a function that converts camelCase input to snake_case while handling acronyms and numbers correctly.

strings case-conversion parsing
+10 pts 15m
Strings & Text easy

Remove punctuation

Write a function that removes all ASCII punctuation characters from a string.

strings punctuation cleaning
+10 pts 10m
Strings & Text easy

Is pangram

Write a function that determines whether a given string is a pangram, ignoring case and non-letter characters.

strings sets algorithm
+8 pts 12m
Strings & Text easy

Caesar Cipher Shift

Implement a function to apply a Caesar cipher shift to a string, preserving case and ignoring non-letters.

strings ascii cipher
+10 pts 15m
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

Is isogram

Implement a function that determines whether a string is an isogram (no repeated letters, case-insensitive).

strings case-insensitive validation
+10 pts 10m
Strings & Text easy

Kebab Case a Phrase

Implement a function that converts a phrase into lowercase kebab-case, handling spaces, punctuation, and camelCase.

strings case-conversion regex
+10 pts 15m
Strings & Text easy

Find all indexes of a substring

Write a function that returns a list of all starting indexes where a substring appears in a string, including overlapping occurrences.

substring string searching
+10 pts 15m
Strings & Text easy

Remove Consecutive Duplicate Letters

Implement a function that removes consecutive duplicate letters from a string, keeping only one occurrence of each run.

strings loops manipulation
+10 pts 15m
Strings & Text easy

Is rotation of another string

Write a function to determine if one string is a rotation of another string.

strings rotation membership
+10 pts 15m
Strings & Text easy

Count words in a sentence

Implement a function to count words in a sentence, ignoring extra whitespace and handling empty strings.

strings split counting
+10 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

Caesar Cipher Shift

Write a function that shifts letters in a string by a given amount, preserving case and ignoring non-letters.

caesar string cipher
+8 pts 10m
Strings & Text easy

Count consonants

Write a function that counts the number of consonant letters in a string.

strings counting loops
+10 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

Extract digits from string

Write a function that extracts all digit characters from a given string, preserving their original order.

strings digits parsing
+6 pts 8m
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

Capitalize First Letter

Write a function that capitalizes the first letter of each word in a string.

string capitalization title
+8 pts 10m
Strings & Text easy

Snake case converter

Implement a function that converts a string to snake_case according to given rules.

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

Camel Case Converter

Write a function that converts a space-separated phrase into lower camelCase.

strings casing manipulation
+8 pts 10m
Strings & Text easy

Kebab Case Converter

Implement a function that converts any string to kebab-case, handling spaces, underscores, camelCase, and punctuation.

strings case-conversion parsing
+8 pts 15m
Strings & Text easy

Is isogram?

Write a function that checks whether a given word is an isogram, ignoring letter case and only considering alphabetic characters.

strings case-insensitive set
+8 pts 12m
Strings & Text easy

Rotate String Right

Implement a function that rotates a given string to the right by a specified number of positions, handling shifts larger than the string length.

strings rotation slicing
+8 pts 10m
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

Expand compressed string

Implement a function that expands run-length encoded strings (e.g., 'a3b2' → 'aaabb').

strings parsing run-length-encoding
+10 pts 15m
Strings & Text easy

Find substring index

Implement a function that returns the starting index of the first occurrence of a substring using only basic string indexing and slicing.

string search index
+10 pts 15m
Strings & Text easy

Count Substrings

Implement a function that counts non-overlapping occurrences of a substring in a given string.

strings counting substrings
+10 pts 15m
Strings & Text easy

Sort characters in string

Write a function that sorts the characters in a string and returns the sorted string.

sorting string character
+8 pts 10m
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

Error message formatter

Write a function that constructs a formatted error message from a code, an optional context, and a fallback message.

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

Stack Trace Sanitizer

Implement a function that rewrites traceback file paths to basenames only.

strings regex parsing
+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 Quoted Strings

Write a function that extracts the text inside every double-quoted substring from a given string.

strings parsing quotes
+8 pts 12m
Strings & Text easy

Normalize Whitespace

Write a function that normalizes any whitespace in a string to single spaces and trims the ends.

strings whitespace split-join
+5 pts 10m
Strings & Text easy

Strip Leading Zeros

Write a function that strips leading zeros from a string representing a non-negative integer.

strings strip lstrip
+5 pts 5m
Strings & Text easy

Find all numbers in text

Write a function that extracts all standalone integers from a text string using regular expressions.

regex parsing numbers
+8 pts 12m
Strings & Text easy

Extract file extensions

Implement a function that extracts the extension from a filename according to standard rules.

strings parsing file-paths
+8 pts 10m
Strings & Text easy

Validate username format

Implement a function that validates a username according to length, allowed characters, and no consecutive underscores.

strings validation returns
+8 pts 12m
Strings & Text easy

Replace template variables

Implement a function that replaces {{variable}} placeholders in a string using a dictionary, leaving unknown placeholders intact.

string-manipulation parsing template
+10 pts 15m
Strings & Text easy

Hamming Distance

Implement a function that computes the Hamming distance between two strings of equal length.

strings character-comparison distance
+10 pts 15m
Lists & Arrays easy

Chunk a list into n-sized parts

Write a function that divides a list into sublists of at most n elements.

list chunking slicing
+10 pts 15m
Lists & Arrays easy

Rotate Left by k

Implement a function that rotates a list left by k positions.

rotation lists slicing
+10 pts 15m
Lists & Arrays easy

Interleave Two Lists

Write a function that interleaves two lists element by element, preserving order.

lists merge indexing
+10 pts 10m
Lists & Arrays easy

Running Maximum

Implement a function that returns a list where each element is the largest value seen so far.

lists cumulative maximum
+10 pts 15m
Lists & Arrays easy

Insert into a Sorted List

Implement a function that inserts a value into a sorted list at the correct position using binary search.

lists binary-search insertion
+10 pts 10m
Lists & Arrays easy

Zip lists into pairs

Write a function that takes two lists and returns a list of two-element sublists pairing elements by index up to the shortest length.

zip lists pairs
+7 pts 10m
Lists & Arrays easy

Middle Element of an Odd-Length List

Implement a function that returns the middle element of an odd-length list.

lists indexing basic
+5 pts 5m
Lists & Arrays easy

Is Subset of Another List

Write a function that returns True if every element in a given list exists in another list, ignoring duplicates.

subset membership lists
+8 pts 12m
Lists & Arrays easy

Unzip pairs into two lists

Write a function that takes a list of pairs and returns two separate lists: first elements and second elements.

zip unpacking lists
+10 pts 10m
Lists & Arrays easy

Generate a Multiplication Table

Build a function that returns an n x n multiplication table as a list of lists.

nested-loops list-comprehension matrix
+10 pts 10m
Lists & Arrays easy

Majority Element Finder

Implement a function that returns the majority element in a list, which appears more than half the time.

majority frequency arrays
+10 pts 15m
Lists & Arrays easy

Union of Two Lists

Implement a function that combines two lists and returns only unique elements.

union list set
+10 pts 15m
Lists & Arrays easy

Difference of Two Lists

Write a function that returns items in list a that are not in list b, preserving order and duplicates.

lists difference counting
+8 pts 10m
Lists & Arrays easy

Chunk list into groups

Implement a function that splits a list into sublists of a given size.

list slicing chunking
+10 pts 10m
Lists & Arrays easy

Zip Two Lists

Write a function that pairs elements from two lists by index, stopping at the shorter list.

zip lists pairs
+8 pts 10m
Lists & Arrays medium

Partition Array

Implement a function that finds a contiguous partition of a list into k groups, minimizing the maximum sum of the groups.

arrays partition contiguous
+25 pts 25m
Lists & Arrays easy

Rearrange Positives and Negatives

Write a function that rearranges a list in-place so all negative numbers come before non-negative numbers.

in-place two-pointers partition
+10 pts 15m
Lists & Arrays easy

Last occurrence index

Implement a function that returns the last index of a given value in a list, or -1 if the value is not present.

lists indexing search
+10 pts 10m
Dicts & Sets easy

Merge dicts summing values

Write a function that merges two dictionaries by summing values for duplicated keys.

dicts merge sum
+10 pts 10m
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

Word to Index Map

Create a function that returns a dictionary mapping each unique word to the index of its first occurrence.

dictionary mapping indexing
+10 pts 10m
Dicts & Sets easy

Missing keys default zero

Write a function to sum numeric values from dictionaries, treating missing keys as zero.

dictionaries sum defaults
+10 pts 12m
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

Common Keys of Two Dictionaries

Implement a function that finds keys shared by two dictionaries and returns them sorted.

dict set sorting
+8 pts 10m
Dicts & Sets easy

Union of Many Sets

Implement a function that takes any number of sets and returns a sorted list of their union.

sets union flatten
+10 pts 10m
Dicts & Sets easy

Mode of a list via counting

Implement a function that returns the mode of a list, resolving ties by the element that appears first.

counting dictionaries mode
+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

Symmetric Difference

Write a function that computes the symmetric difference of two lists, returning a sorted list of unique elements.

sets set-operations symmetric-difference
+8 pts 10m
Dicts & Sets easy

Subset of another set

Write a function that checks if every element of one set is contained in another.

sets subset membership
+10 pts 10m
Dicts & Sets easy

Frequency sort descending

Write a function that sorts a list by frequency descending while preserving original order for ties.

frequency sorting dict
+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 medium

Hash map merge

Write a function that merges two dictionaries recursively, combining values and preserving structure.

dictionaries recursion merging
+15 pts 15m
Functions & Closures medium

Memoize decorator

Implement a @memoize decorator that caches results of a function.

decorators closures caching
1
+25 pts 20m
Functions & Closures medium

Function composition

Return a function that applies f after g: compose(f, g)(x) == f(g(x)).

functional closures higher-order
+20 pts 18m
Functions & Closures hard

Curry a function

Auto-curry any multi-argument function so it returns partial applications until fully saturated.

functional closures inspect
+35 pts 30m
Functions & Closures easy

Bind First Argument

Implement bind_first_arg, a decorator that fixes the first argument of any function.

decorators closures functions
+10 pts 15m
OOP & Classes medium

Linked list reversal

Implement a singly linked list and a function to reverse it in place.

linked-list OOP pointers
+28 pts 25m
OOP & Classes easy

Event emitter basics

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

oop callbacks events
+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
Data Structures & Algorithms hard

LRU cache decorator

Implement @lru_cache(maxsize=N) for unary functions using OrderedDict.

decorators caching OrderedDict
1
+50 pts 40m
Data Structures & Algorithms easy

Index of peak element

Implement a function that returns the index of any peak element in a given integer array.

arrays search peak
+10 pts 15m
Data Structures & Algorithms medium

Count inversions lite

Implement a function that counts inversions in a list of numbers efficiently.

inversions sorting merge sort
+25 pts 25m
Data Structures & Algorithms medium

Find Peak Element

Implement a function that returns the index of any peak element in an integer array.

arrays search binary-search
+20 pts 25m
Advanced Python medium

Retry decorator

Implement @retry(times=3) that retries a function on exception.

decorators error-handling
+28 pts 25m
Advanced Python hard

Data pipeline

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

functional OOP pipeline
1
+40 pts 35m
Iterators & Generators easy

Generator Pipeline

Implement a generator function that yields only even numbers from an input list, squared.

generators lazy-evaluation filter
+8 pts 12m
Iterators & Generators easy

Fibonacci Generator

Create a generator function that yields Fibonacci numbers from 0 upward until a given limit.

generator fibonacci lazy evaluation
+8 pts 10m
Iterators & Generators medium

Prime Sieve Generator

Implement a generator function that yields prime numbers from 2 up to a specified limit, using an efficient sieve approach.

generators prime sieve
+20 pts 20m
Iterators & Generators easy

Pairwise Sequence Pairs

Write a generator function pairwise that yields each consecutive overlapping pair from any iterable as lists.

generators iterators pairs
+10 pts 15m
Iterators & Generators easy

Groupby Consecutive

Write a generator function that yields (value, list_of_occurrences) for each run of consecutive equal items.

generator groupby consecutive
+8 pts 12m
Iterators & Generators easy

Collatz Generator

Implement a generator function that yields the Collatz sequence starting from a given positive integer.

generators collatz sequence
+10 pts 10m
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 easy

Tree inorder generator

Write a generator function that yields a binary tree's node values in inorder traversal.

generator inorder binary-tree
+10 pts 15m
Decorators & Context Managers easy

Once Decorator: Run a Function Only Once

Implement a decorator that caches and returns the result of the first call for subsequent calls.

decorators closures caching
+8 pts 10m
Decorators & Context Managers easy

Timing Decorator

Implement a decorator that prints the execution time of a function.

decorators time performance
+10 pts 15m
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 medium

LRU Memoize

Implement an LRU memoization decorator that caches results for a fixed number of arguments.

decorators caching lru
+30 pts 25m
Decorators & Context Managers medium

Rate Limit Decorator

Implement a decorator that enforces a maximum number of calls per second for any function.

decorator time rate-limiting
+20 pts 20m
Decorators & Context Managers medium

Cache result decorator

Create a decorator that stores results of function calls keyed by positional arguments.

decorators memoization functools
+20 pts 20m
Decorators & Context Managers medium

Profile time decorator

Create a decorator that tracks how many times a function is called and its cumulative execution time.

decorators timing profiling
+20 pts 20m
Decorators & Context Managers easy

Print Args Decorator

Write a decorator that prints function name and arguments, then returns the original result.

decorators functions wrappers
+10 pts 10m
Error Handling & Exceptions easy

Safe divide function

Implement safe_divide that returns None on ZeroDivisionError and TypeError.

try-except division error-handling
+8 pts 10m
Error Handling & Exceptions easy

Safe Float Parser

Write a function that safely converts a string to a float, returning None for invalid inputs.

float exception parsing
+10 pts 10m
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
Error Handling & Exceptions easy

Key error handler

Implement a safe dictionary access function that returns a default value on missing keys.

exceptions dict fallback
+8 pts 10m
Error Handling & Exceptions easy

Else on try block

Implement a function that uses try-except-else to safely divide two numbers and return a result or error description.

exception-handling try-except-else division
+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

Validate phone number

Write a function that uses regular expressions to determine if a given string is a valid US phone number.

regex validation phone
+10 pts 15m
Regular Expressions easy

Match IPv4 Address

Write a function that uses a regular expression to check if a string is a valid IPv4 address.

regex validation ipv4
+8 pts 12m
Regular Expressions hard

Match IPv6 Address

Write a function that uses a regex to validate whether a string is a fully expanded IPv6 address.

regex validation ipv6
+25 pts 30m
Regular Expressions medium

Match Credit Card Pattern

Write a function that validates a credit card number string against a set of formatting rules.

regex validation credit-card
+25 pts 25m
Regular Expressions easy

Validate Hex Color Code

Write a function that validates hex color codes using regular expressions.

regex validation strings
+10 pts 10m
Regular Expressions easy

Lookahead Validation

Write a regex-based function to check if a password meets length and character class requirements.

regex lookahead validation
+8 pts 10m
Math & Number Theory easy

Nth Triangular Number

Implement a function that returns the nth triangular number efficiently.

math formula integers
1
+10 pts 10m
Math & Number Theory easy

Integer Square Root Floor

Implement a function that returns the greatest integer whose square is ≤ n, using only integer operations.

math binary-search integer
+8 pts 12m
Math & Number Theory easy

Catalan number

Implement a function that returns the nth Catalan number using dynamic programming.

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

Stirling number

Implement a function to compute Stirling numbers of the second kind S(n,k).

stirling-numbers dynamic-programming combinatorics
+10 pts 15m
Math & Number Theory easy

Euler Totient Function

Implement Euler's totient function φ(n) for positive integers.

math number-theory totient
+10 pts 15m
Math & Number Theory easy

Perfect Number Check

Write a function that returns True if a number is perfect, i.e., equal to the sum of its proper divisors.

math divisors number-theory
+10 pts 15m
Math & Number Theory easy

Abundant Number Check

Implement a function to check whether a given integer is abundant: sum of proper divisors exceeds the number.

math divisors number-theory
+10 pts 15m
Math & Number Theory easy

Amicable Numbers Check

Write a function that checks if two numbers are an amicable pair by comparing sums of proper divisors.

divisors arithmetic math
+10 pts 15m
Math & Number Theory easy

Armstrong Number Check

Implement a function that checks if a given integer is an Armstrong number.

arithmetic number-theory validation
+10 pts 10m
Math & Number Theory easy

Happy number check

Implement a function that returns True if a number is happy, False otherwise.

math loops set
+8 pts 12m
Math & Number Theory easy

Harshad Number Check

Write a function that checks if a number is a Harshad (or Niven) number.

math digits divisibility
+8 pts 10m
Math & Number Theory medium

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.

prime factors digit sum number theory
+20 pts 25m
Math & Number Theory easy

Triangular Number

Implement a function that returns the nth triangular number using the closed-form formula.

triangular formula math
+10 pts 10m
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

Partition function

Write a function that returns the number of ways to write a positive integer as a sum of positive integers (order irrelevant).

math recursion memoization
+12 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
Bit Manipulation easy

Count Set Bits

Implement a function that returns the number of set bits (1s) in the binary representation of a non-negative integer.

bit-manipulation binary counting
+10 pts 15m
Bit Manipulation easy

Gray Code Encode

Implement a function that converts a non-negative integer to its Gray code representation using bitwise XOR and shift.

bitwise gray-code encoding
+10 pts 15m
Bit Manipulation easy

Find Rightmost Set Bit

Implement a function that returns the 1-indexed position of the rightmost set bit of a positive integer, or 0 if none.

bitwise bit-manipulation integer
+8 pts 12m
Bit Manipulation easy

Rotate Bits Left

Implement a function that rotates the bits of an integer to the left by a specified number of positions.

bit-manipulation integer rotation
+10 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

Bit Mask Permissions

Implement helper functions to compose bit masks and check permission bits using bitwise operators.

bitwise bitmasks permissions
+15 pts 20m
Bit Manipulation easy

Set kth Bit

Implement a function that sets the kth bit (0-indexed) of a non-negative integer to 1 and returns the result.

bit-manipulation bits integer
+10 pts 15m
Bit Manipulation easy

Clear kth Bit

Implement a function that clears the k-th bit of a non-negative integer (turns it to 0) using bitwise operations.

bit mask integer
+10 pts 10m
Bit Manipulation easy

Compress Bits Run

Write a function that compresses a binary string by representing consecutive identical bits as a count-bit pair.

bit-manipulation strings compression
+10 pts 15m
Bit Manipulation easy

Brian Kernighan count

Implement a function that counts set bits using Brian Kernighan's efficient algorithm.

bit-manipulation integers counting
+10 pts 15m
Dynamic Programming medium

Bell number

Implement a function to compute the Bell number B(n) using dynamic programming.

dp combinatorics math
+25 pts 25m
Dynamic Programming easy

Climbing Stairs

Implement a function that returns the number of distinct ways to climb n stairs using steps of 1 or 2.

fibonacci dp counting
+10 pts 15m
Dynamic Programming medium

Target Sum Subsets

Write a function that counts the number of subsets of a list of positive integers that sum exactly to a target.

subset-sum dp counting
+25 pts 30m
Dynamic Programming medium

Word Break DP

Implement a function to check if a string can be segmented into space-separated dictionary words.

dynamic-programming strings word-break
+20 pts 25m
Trees & Binary Trees easy

Binary Tree Inorder Traversal

Implement an inorder traversal function that returns node values in left-root-right order.

binary-tree traversal recursion
+10 pts 15m
Trees & Binary Trees easy

Preorder Traversal

Implement a function that returns the preorder traversal values of a binary tree.

binary-tree traversal recursion
+10 pts 10m
Trees & Binary Trees easy

Postorder Traversal

Implement a function that returns the postorder traversal of a binary tree as a list of node values.

binary-tree traversal recursion
+10 pts 15m
Trees & Binary Trees easy

Symmetric Tree Check

Write a function that checks whether a binary tree is symmetric (a mirror of itself).

binary-tree recursion mirror
+10 pts 15m
Trees & Binary Trees easy

Same Tree Check

Write a function that checks whether two binary trees are identical in structure and node values.

binary tree recursion tree traversal
+10 pts 15m
Trees & Binary Trees medium

Lowest Common Ancestor in a Binary Tree

Implement a function to find the lowest common ancestor (LCA) of two nodes in a binary tree.

binary-tree dfs recursion
+30 pts 30m
Trees & Binary Trees medium

Delete Node in BST

Implement a function that deletes a key from a binary search tree and returns the new root.

binary-search-tree tree-traversal recursion
+20 pts 20m
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 easy

Cycle Detection in Undirected Graph

Write a function that detects if an undirected graph contains a cycle.

graph dfs cycle-detection
+10 pts 15m
Graphs & Graph Algorithms medium

Articulation Points

Implement a function that returns the articulation points of an undirected graph.

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

Bridges in Graph

Implement a function that returns all bridges in an undirected graph.

graph dfs bridges
+30 pts 30m
Graphs & Graph Algorithms medium

Hamiltonian Path Check

Implement a function that checks whether an undirected graph has a Hamiltonian path using DFS and backtracking.

graph dfs backtracking
+30 pts 30m
Graphs & Graph Algorithms medium

Bipartite Graph Check

Implement a function to check if an undirected graph is bipartite using graph coloring.

graphs bfs coloring
+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 easy

Find center of star graph

Write a function that finds the center node of a star graph from its list of edges in O(1) time.

graph star-graph array
+10 pts 15m
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 easy

Permutation Generator

Write a function that returns all permutations of a list of distinct integers.

recursion backtracking permutations
+10 pts 15m
Recursion & Backtracking medium

Combination Generator

Write a recursive function that returns all combinations of length k from a list of distinct integers.

recursion backtracking combinations
+25 pts 25m
Binary Search medium

Ternary Search

Implement ternary search to locate the maximum of a discrete unimodal function.

ternary-search binary-search unimodal
+25 pts 30m
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
Datetime & Time Calculations easy

Days in month

Write a function that returns the number of days in a given month and year, correctly handling leap years.

datetime calendar leap-year
+8 pts 10m

Showing 222 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.