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 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 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 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 easy

Remove duplicates (sorted)

Return a sorted list with duplicates removed.

arrays two-pointer
+10 pts 10m
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 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 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 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
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 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 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 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 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 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
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 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
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
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
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 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
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
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 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 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
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 101 challenges · easy

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.