Factorial (iterative)
Compute n! iteratively without recursion.
Clamp a Number to a Range
Implement a clamp function that returns a value within a specified range.
Max of a variable-length list
Implement a function that returns the maximum value from a list of numbers without using max().
Replace negatives with zero
Implement a function that replaces all negative numbers in a list with zero.
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.
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.
Modulo Remainder
Implement a function that returns the remainder of a divided by b without using the modulo operator.
Digit Count
Count the number of digits in an integer using arithmetic, without string conversion.
Find Missing Number
Given a list of n distinct integers from 0..n with one missing, return the missing number.
Enumerate with start
Implement a function that mimics Python's enumerate with a custom start index.
Convolve 1D signal
Implement a 1D convolution function with three modes using pure Python.
Guess Number Game
Simulate a number guessing game with attempts, feedback, and a win/lose result.
Broadcast Add Scalar
Add a scalar to every number in a 2D list and return a new 2D list without modifying the original.
Reshape array dimensions
Implement a function that reshapes a 1D list into a 2D list with given dimensions.
Title case converter
Return the string with each word capitalised.
Longest word in a sentence
Write a function that returns the longest word from a sentence, with first-occurrence tie-breaking.
Replace vowels with stars
Write a function that replaces every vowel in a given string with an asterisk.
Normalize quotes
Replace all typographic quote characters with straight ASCII quotes.
Interleave Two Strings
Given two strings s1 and s2, return a new string that interleaves them character by character, starting with s1.
Center a string in a width
Write a function that centers a string within a specified width by adding spaces on both sides.
Remove Duplicates from String
Given a string, return a new string with each character that repeats consecutively reduced to a single occurrence.
Longest Word Finder
Write a function that extracts alphabetic words from a string and returns the longest one, with ties broken by earliest position.
Abbreviate Name
Create a function that takes a full name and returns an abbreviated version with initials and the last name.
Replace Spaces with Dashes
Write a function that replaces every space in a string with a dash.
Compress Consecutive Chars
Write a function that compresses a string by replacing runs of identical characters with the character followed by the count.
Index of First Occurrence
Implement a function that finds the starting index of a substring within a string, returning -1 when absent.
Parse Log Line
Write a function that parses a log line and returns a dictionary with timestamp, level, and message.
Replace multiple spaces
Implement a function that replaces every sequence of spaces with a single space.
Extract domain from URL
Extract the domain (hostname without port or www) from a given URL string.
Parse URL components
Write parse_url that splits a URL into its standard components with defaults for missing parts.
Decode base64 string
Write a function that decodes a base64 string to its original UTF-8 text without using the base64 module.
User Friendly Message
Given a raw user input, format it into a single clean sentence with proper sentence case and trimming.
Two Sum
Return indices (i, j) with i < j such that nums[i] + nums[j] == target.
Remove duplicates (sorted)
Return a sorted list with duplicates removed.
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.
Pad Array Edges
Write a function that pads a list with zeros on both ends.
Sort array by parity
Given a list of integers, return a new list with all evens first and odds last, preserving original relative order.
Linear Interpolation Array
Given an array with some None values, replace them by linear interpolation between the nearest known values.
Are two lists the same multiset
Write a function that checks if two lists contain the same elements with the same multiplicities, ignoring order.
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.
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.
Top k keys by count
Given a dictionary mapping keys to counts, return the top k keys with the highest counts, breaking ties alphabetically.
Replace keys with a mapping
Write a function that renames keys in a dictionary according to a mapping, with duplicate handling.
Two Sum with Dict
Implement the classic Two Sum problem: return indices of two numbers that add up to a target using a dict.
Sort by frequency
Sort a list by element frequency descending, with ties broken by order of first occurrence.
Pair with difference K
Count unordered index pairs with absolute difference exactly K, handling duplicates correctly.
Count Pairs with Sum
Implement a function that counts the number of distinct pairs in a list summing to a target.
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.
Pivot sales by product
Write a function that pivots sales records into a dictionary keyed by product with monthly totals.
Stack class
Implement a Stack class with push, pop, peek, is_empty, and size.
Event emitter basics
Implement an EventEmitter class with subscribe/emit/unsubscribe functionality.
Rectangle class
Implement a Rectangle class with properties, methods, and special methods for basic geometry and comparison.
Queue class (list-based)
Implement a Queue class with enqueue, dequeue, peek, is_empty, and is_full methods using a list.
Abstract Base Class
Create an abstract Shape class and implement Rectangle and Circle subclasses with area and perimeter.
Deck of Cards Class
Implement a Deck class representing a standard 52-card deck with shuffle, deal, and len support.
Dataclass with slots
Implement a slotted frozen dataclass representing a 2D point with total ordering.
Playing card class
Design a PlayingCard class with suit, rank, color, and equality/comparison magic methods.
Count pairs with given difference
Count how many unordered pairs in a list have a given absolute difference using an efficient approach.
Previous Smaller Element
Find the nearest previous index with a smaller value for every element in an array.
Union Find Class
Implement a UnionFind class with find and union operations supporting path compression and union by size.
Delete Old Records
Filter a list of records by removing those with a date older than a given cutoff date.
Argsort Indices
Implement a function that returns the indices that would sort a list of integers, with ties broken by original order.
Default Argument Trap
Implement a function that safely accumulates items without the classic mutable default argument bug.
Range-like generator
Implement a custom generator that yields numbers like Python's range but with flexible bounds.
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.
Zip Longest Fill
Create an iterator that yields lists from multiple iterables, padding with a fill value when lengths differ.
Graph DFS Generator
Implement a generator function that performs a depth-first traversal of a graph without recursion.
Context Manager Class
Implement a context manager class that measures execution time and sets duration, with None if an exception occurred.
Timer Context Manager
Implement a context manager that measures execution time of a with block and stores it.
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.
Divide with zero check
Write a function that safely divides two numbers, catching division by zero.
Multiline anchor match
Extract lines beginning with a plain-text prefix from multiline strings using Python's re module.
Match Balanced Parentheses with Regex
Write a function that uses regular expressions to determine if parentheses are balanced and properly nested.
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.
Lucas Sequence
Implement a function to compute the n-th Lucas number using iteration or recursion with memoization.
Multiply without multiply
Write a function that multiplies two integers using only addition, subtraction, and bit shifts — no * operator.
Chinese Remainder Theorem
Solve a system of congruences with pairwise coprime moduli using the Chinese Remainder Theorem.
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.
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.
Isolate Rightmost Set Bit
Given an integer, return a number with only its rightmost set bit set.
Add without plus
Implement a function that adds two integers using only bitwise operations, no arithmetic plus or minus.
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.
House Robber
Given a list of house values, return the maximum sum you can rob without robbing two adjacent houses.
Range Sum BST
Return the sum of all node values in a BST that lie within a given inclusive range [low, high].
Cycle Detection in a Directed Graph
Use DFS with a recursion stack to detect cycles in a directed graph.
Wildcard Match (Simple)
Write a function that checks whether a string matches a pattern with '*' and '?' wildcards.
Maximize units on truck
Given box types with count and units per box, maximize total units loaded onto a truck.
Longest Substring Without Repeating Characters
Implement a function that returns the length of the longest substring without repeating characters.
Container With Most Water
Compute the maximum area between two vertical lines in an array of heights.
Max Stack Design
Implement a MaxStack class with push, pop, top, and get_max operations.
Min Heap Class
Build a MinHeap class with push, pop, peek, and size methods that maintain a valid min-heap.
Age in years months days
Given birth and reference dates, return age as a dictionary with years, months, days.
Week Number ISO
Given a date, return its ISO 8601 week number (1–53) without using datetime.isocalendar().
Generate CSV row
Implement a function that converts a list of values into a single CSV row with correct quoting and escaping.
Parse YAML-like dict
Parse a simple YAML-like text with indentation into a nested dictionary.
Encode Base64 String
Write a function that encodes a UTF-8 string into a base64 string without using the base64 module.
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.
Customers Never Order
Given Customers and Orders tables, return the names of customers with no orders, sorted alphabetically, or None if all have ordered.
Constant Time Compare
Write a function that compares two strings without leaking length or content via timing.
Password Salt Hash
Implement a function that returns a secure salted SHA-256 password hash with a deterministic format.
XOR Cipher Encode
Implement the XOR cipher: encode a string by XORing each character with a key character.
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
- Pick a category — basics, algorithms, strings, and more
- Open a challenge, read the statement, and edit the starter code
- Run tests, fix failures, then try a related quiz or tutorial lesson
Challenges vs tutorials and quizzes
Challenges test what you can build under constraints. For guided teaching, use our Python tutorials. For quick checks, try quizzes or copy snippets from code samples.