Practice Arena

Python Coding Challenges

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

875 challenges 536 easy 303 medium 36 hard
Python Basics easy

FizzBuzz, precisely

Return a newline-separated string for 1..n: Fizz, Buzz, FizzBuzz, or the number.

control flow strings modulo
2
+10 pts 12m
Python Basics medium

Fibonacci(n)

Return the nth Fibonacci number efficiently.

recursion dp memoization
+15 pts 15m
Python Basics easy

Prime checker

Return True if n is a prime number.

math loops
1
+10 pts 10m
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

Min of three numbers

Write a function that returns the minimum of three integers.

min comparison function
+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

Digit count of an integer

Given an integer, return the number of digits it has, handling negatives and zero correctly.

integers loops arithmetic
+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

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

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

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

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

Count Positives

Count the positive numbers in a list of integers.

conditionals loops basic
+10 pts 10m
Python Basics easy

Range of values

Calculate the range (max minus min) of a list of numbers. Empty list returns 0.

min max numbers
+10 pts 10m
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

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

Variadic Sum Function

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

functions args sum
+10 pts 10m
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
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

Parse environment variables

Write parse_env_vars that parses KEY=VALUE lines into a dict, converting booleans/numbers and ignoring comments.

strings parsing dictionaries
+8 pts 15m
Python Basics easy

Array mean and std

Implement the function array_stats that returns the mean and population standard deviation of a list of numbers.

statistics mean std
+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

Cumulative Sum Vectorized

Implement a function that returns the cumulative sum of a list of numbers.

lists cumulative sum
+10 pts 10m
Python Basics easy

Percentile Calculation

Given a list of numbers and a target value, return the percentile rank of that value in the list.

lists statistics math
+8 pts 10m
Strings & Text easy

Count vowels

Count the number of vowels (a, e, i, o, u) in a string (case-insensitive).

strings counting
+5 pts 5m
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

Count consonants

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

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

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

Caesar Cipher Decrypt

Implement a function that decrypts a Caesar cipher by shifting letters back by a given number.

strings ascii cipher
+10 pts 15m
Strings & Text easy

Parse numbered list

Take a string containing a numbered list and return a clean list of the item texts.

string parsing strip split
+8 pts 12m
Strings & Text easy

Parse range notation

Parse a comma-separated list of ranges and individual numbers, expanding each range into its full sequence.

strings parsing ranges
+8 pts 12m
Strings & Text medium

Additive number sequence

Check whether a given digit string can be partitioned into a valid additive sequence where each term is the sum of the previous two.

strings parsing fibonacci
+30 pts 25m
Lists & Arrays easy

Move Zeros to the End

Reorder a list in-place, pushing all zeros to the end while preserving the order of non-zero numbers.

lists in-place two-pointer
+10 pts 15m
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

Difference of Consecutive Elements

Given a list of numbers, return a new list where each element is the difference between consecutive elements.

list iteration math
+8 pts 10m
Lists & Arrays easy

Find Second Largest

Find the second largest unique number in a list, or None if it doesn't exist.

sorting max unique
+10 pts 10m
Lists & Arrays medium

Find Duplicate Number

Given a list of n+1 integers in the range 1..n, find the one integer that appears more than once.

arrays hash-set duplicates
+20 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 medium

Two Missing Numbers

Given a list of n-2 unique integers from 1 to n, find the two missing numbers efficiently.

missing-numbers arrays math
+25 pts 25m
Lists & Arrays medium

Three Missing Numbers

Find the three missing numbers from a shuffled list containing all but three integers from 1 to n.

arrays sets missing
+15 pts 15m
Lists & Arrays medium

Count Smaller Numbers

Given an integer list, return for each position how many later elements are smaller than it.

arrays counting merge-sort
+20 pts 20m
Lists & Arrays easy

Convert Binary Number List

Given a list of bits (0s and 1s) in most-significant-first order, return the equivalent integer value.

binary lists conversion
+8 pts 10m
Lists & Arrays easy

Intersection two lists length

Return the number of distinct elements that appear in both input lists.

lists sets intersection
+8 pts 10m
Lists & Arrays easy

Normalize Array to Zero-One Range

Implement a function that normalizes a list of numbers to the range [0,1] using min-max scaling.

arrays normalization scaling
+8 pts 12m
Lists & Arrays easy

Rolling Window Mean

Given a list of numbers and a window size k, return a list of the means of every contiguous subarray of length k.

sliding-window lists averaging
+10 pts 12m
Dicts & Sets medium

Subarray sum equals K

Count the number of contiguous subarrays whose sum equals k.

prefix-sum dict arrays
+28 pts 25m
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

Values that appear once

Return a list of numbers that appear exactly once in the input list, in original order.

counting filtering order
+10 pts 15m
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

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
OOP & Classes medium

Complex Number Class

Implement a Complex class supporting addition, subtraction, multiplication, division, equality, and string formatting.

classes magic-methods arithmetic
+20 pts 25m
Data Structures & Algorithms medium

Coin change (DP)

Find the minimum number of coins to make exactly the target amount.

dp greedy
+30 pts 28m
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 easy

Employee Hierarchy

Build an employee hierarchy tree and compute the total number of direct and indirect reports for each employee.

tree dfs graph
+10 pts 15m
Data Structures & Algorithms easy

Bubble Sort

Implement bubble sort that sorts a list of numbers in ascending order.

sorting arrays algorithms
+8 pts 12m
Data Structures & Algorithms easy

Selection Sort Implementation

Implement selection sort to sort a list of numbers in ascending order.

sorting selection-sort algorithm
+10 pts 15m
Data Structures & Algorithms medium

Merge Sort

Implement merge_sort(numbers) that returns a sorted copy of the input list using the merge sort algorithm.

sorting recursion divide-and-conquer
+30 pts 30m
Data Structures & Algorithms medium

Bucket Sort

Implement bucket sort to sort a list of floating-point numbers in the range [0,1).

sorting bucket-sort insertion-sort
+25 pts 30m
Data Structures & Algorithms medium

Decode Ways

Count the number of ways to decode a numeric string into letters using the mapping A=1 to Z=26.

dynamic programming strings counting
+20 pts 25m
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 medium

Eulerian Path Check

Given the number of vertices and an edge list of an undirected graph, decide if it has an Eulerian path.

graph eulerian degree
+25 pts 25m
Data Structures & Algorithms hard

N-Queens Solutions

Implement a function to count the number of distinct ways to place n queens on an n×n board.

backtracking chess recursion
+40 pts 35m
Data Structures & Algorithms medium

Strobogrammatic number II

Given a positive integer n, return all strobogrammatic numbers of length n in ascending order.

strings recursion number
+25 pts 20m
Advanced Python medium

Multiprocessing Queue

Implement a function that uses a multiprocessing queue to compute factorials of a list of numbers in parallel.

multiprocessing queue parallel
+25 pts 25m
Iterators & Generators easy

Custom iterator class

Implement a custom iterator class that repeatedly yields elements from a list up to a given number of times.

iterator class cycle
+10 pts 15m
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

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

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

Iterator protocol class

Implement a class that follows the iterator protocol and yields squared numbers up to a given limit.

iterator-protocol class lazy-evaluation
+10 pts 10m
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
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

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

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

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

Prime Factorization

Return a sorted list of prime factors of a positive integer, including repeated factors.

prime math loops
+10 pts 15m
Math & Number Theory easy

Count divisors

Compute the number of positive divisors of a given integer using its prime factorization.

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

Sum of divisors

Given an integer n, return the sum of all its positive divisors.

divisors math number-theory
+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

Pentagonal Number

Given a positive integer n, return the nth pentagonal number using the formula P(n) = n(3n - 1)/2.

math formula integer
+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 medium

Extended Euclidean Algorithm

Implement the extended Euclidean algorithm to return (gcd, x, y) such that ax + by = gcd(a, b).

gcd extended-euclidean number-theory
+30 pts 25m
Math & Number Theory easy

Deficient Number Check

Write is_deficient(n) that returns True if the sum of proper divisors is less than n.

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

Kaprekar number check

Check whether a given non-negative integer is a Kaprekar number in base 10.

math number-theory integer-properties
+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
Math & Number Theory medium

Correlation Coefficient

Write a pure-Python function that computes the Pearson correlation coefficient between two lists of numbers.

statistics math arrays
+15 pts 15m
Math & Number Theory easy

Z score normalization

Compute the z-scores for a list of numbers using the population standard deviation.

statistics math standard-deviation
+8 pts 10m
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

Single Number XOR

Given a non-empty list of integers where every element appears twice except one, return the single number using XOR.

xor bit-manipulation arrays
+10 pts 12m
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

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

Sparse Number Check

Check if a non-negative integer is sparse, meaning its binary representation contains no adjacent 1 bits.

bitwise binary conditionals
+10 pts 15m
Bit Manipulation medium

Maximum XOR Pair

Implement max_xor_pair(nums) that returns the maximum XOR value obtainable by pairing any two numbers in the given list.

bit-manipulation xor array
+25 pts 30m
Bit Manipulation easy

Odd Parity Bit

Given an integer, return the odd parity bit (0 or 1) so that total number of 1-bits in the 8-bit representation becomes odd.

bitwise parity integer
+8 pts 10m
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 easy

Unique Paths in a Grid

Count the number of unique paths from the top-left corner to the bottom-right corner of a grid, moving only right and down.

dynamic-programming grid counting
+15 pts 20m
Dynamic Programming medium

Edit Distance (Levenshtein Distance)

Implement the classic edit distance algorithm to find the minimum number of single-character edits required to transform one string into another.

dynamic-programming strings levenshtein-distance
+25 pts 30m
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

Coin Change Minimum

Given coin denominations and a target amount, compute the minimum number of coins needed or -1 if impossible.

dynamic-programming coins minimum
+30 pts 25m
Dynamic Programming medium

Coin Change Ways

Count the number of distinct combinations of coins that sum to a target amount.

dynamic programming coins counting
+30 pts 25m
Dynamic Programming medium

Perfect Squares Sum

Given a positive integer n, return the least number of perfect squares (e.g., 1, 4, 9, 16, ...) that sum to n.

dynamic-programming math optimization
+25 pts 25m
Dynamic Programming hard

Palindrome Partitioning Minimum Cuts

Given a string, return the minimum number of cuts needed such that every substring in the partition is a palindrome.

dynamic-programming palindrome strings
+40 pts 35m
Dynamic Programming hard

Egg Drop Puzzle

Given k eggs and n floors, compute the minimum number of attempts required in the worst case to find the highest safe floor.

dynamic-programming optimization classic-puzzle
+45 pts 35m
Dynamic Programming hard

Create Maximum Number

Given two arrays of digits and an integer k, merge them to form the largest number of length k.

arrays greedy dynamic-programming
+40 pts 35m
Dynamic Programming medium

Ugly Number II

Given an integer n, return the nth ugly number using an efficient dynamic programming approach.

dynamic programming math pointers
+25 pts 25m
Dynamic Programming medium

Target sum assignments

Given a list of integers and a target, count how many ways to assign + or - to each number so the total equals the target.

dynamic programming combinatorics arrays
+30 pts 25m
Dynamic Programming medium

Delete and Earn

Given an array of integers, find the maximum points you can earn by repeatedly deleting a number and all its adjacent values.

dynamic-programming array hash-map
+30 pts 25m
Trees & Binary Trees medium

Sum Root to Leaf Numbers

Given the root of a binary tree, compute the total sum of all root-to-leaf numbers.

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

Maximum Width of a Binary Tree

Given the root of a binary tree, compute its maximum width (the maximum number of nodes in any level, counting null positions).

binary-tree breadth-first-search queue
+25 pts 25m
Graphs & Graph Algorithms medium

Open the Lock BFS

Implement a BFS solution to find the minimum number of turns needed to open a 4-wheel lock, avoiding a set of deadends.

bfs strings graph
+25 pts 30m
Graphs & Graph Algorithms medium

Minimum Genetic Mutation

Implement a function to compute the minimum number of single-character mutations needed to transform one gene string into another, using a given bank of valid mutations.

bfs graph string
+30 pts 30m
Graphs & Graph Algorithms medium

Graph Coloring Backtrack

Given an adjacency list and a number of colors, decide if the graph can be colored so no adjacent vertices share a color.

backtracking graphs coloring
+30 pts 30m
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

Most stones removed

Given stone coordinates on a grid, find the maximum number of stones that can be removed while every stone shares a row or column with another remaining stone.

graphs dfs union-find
+30 pts 30m
Recursion & Backtracking medium

Letter Combinations of a Phone Number

Given a string of digits, return all possible letter combinations that the number could represent on a phone keypad.

recursion backtracking string
+25 pts 25m
Recursion & Backtracking medium

N-Queens Count

Count the number of distinct valid placements of n non-attacking queens on an n×n chessboard.

backtracking recursion n-queens
+25 pts 30m
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

Letter Tile Possibilities

Given a string of letter tiles, count the number of distinct non-empty sequences that can be formed using any non-empty subset in any order.

backtracking counting strings
+25 pts 25m
Recursion & Backtracking medium

Beautiful Arrangement Count

Count the number of permutations of 1..n such that for every index i, either i is divisible by the number at that position or the number is divisible by i.

recursion backtracking permutations
+30 pts 30m
Recursion & Backtracking medium

Rat in a Maze

Count the number of distinct paths a rat can take from top-left to bottom-right in a binary grid, moving down or right and avoiding walls.

backtracking recursion maze
+25 pts 30m
Greedy Algorithms easy

Assign Cookies

Given child greed factors and cookie sizes, return the maximum number of content children.

greedy sorting two-pointers
+10 pts 15m
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 medium

Meeting Rooms Minimum

Given a list of meeting time intervals, compute the minimum number of conference rooms required.

greedy intervals sorting
+30 pts 25m
Greedy Algorithms medium

Boats to Save People

Given a list of people weights and a boat's weight limit, return the minimum number of boats required.

greedy two-pointers sorting
+25 pts 25m
Greedy Algorithms easy

Maximum Ice Cream Bars

Given costs of ice cream bars and coins, return the maximum number you can buy.

greedy sorting array
+10 pts 15m
Greedy Algorithms medium

Minimum Number of Arrows to Burst Balloons

Given balloon intervals, find the minimum number of arrows to burst all balloons by merging overlaps.

greedy sorting intervals
+25 pts 25m
Greedy Algorithms hard

Patching Array

Given a sorted array of positive integers and a target n, find the minimum number of patches to make every number from 1 to n representable as a subset sum.

greedy arrays prefix-sums
+40 pts 30m
Greedy Algorithms medium

Queue Reconstruction by Height

Given shuffled pairs of (height, number_of_taller_people_in_front), reconstruct the original queue order.

greedy sorting insertion
+25 pts 25m
Greedy Algorithms medium

Non-overlapping Intervals

Given a list of intervals, return the minimum number of intervals to remove to make the rest non-overlapping.

greedy intervals sorting
+20 pts 20m
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

Nth Magical Number

Given three integers n, a, b, return the nth positive integer that is divisible by either a or b.

binary-search math counting
+25 pts 25m
Binary Search medium

Minimum Limit of Balls in a Bag

Given an array of bag sizes and a number of allowed splits, find the minimum possible maximum bag size.

binary-search arrays optimization
+25 pts 25m
Two Pointers & Sliding Window medium

Character Replacement Window

Given a string and a number k, find the length of the longest substring that can be made uniform by replacing at most k characters.

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

Count Nice Subarrays

Given an array of integers, count the number of contiguous subarrays that contain exactly k odd numbers.

sliding-window two-pointers subarray
+25 pts 25m
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 easy

Reduce array to zero

Given an array of non-negative integers, each operation chooses two indices and subtracts 1 from each if both are positive. Return the minimum number of operations to reduce the array to all zeros, or -1 if impossible.

two-pointers arrays greedy
+10 pts 15m
Two Pointers & Sliding Window medium

Closest Three Sum

Given an array of integers and a target, return the sum of three numbers that is closest to the target.

sorting two-pointers array
+20 pts 20m
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

Boats to Save People – Two Pointer

Implement a function that returns the minimum number of boats needed to rescue everyone, given a weight limit and each boat carrying at most two people.

two-pointers sorting greedy
+25 pts 30m
Two Pointers & Sliding Window medium

Count Nice Subarrays

Count subarrays that contain exactly k odd numbers.

sliding-window two-pointers counting
+25 pts 30m
Stacks & Queues medium

Remove K Digits Stack

Remove k digits from a non-negative integer string to produce the smallest possible number using a stack-based approach.

stack string greedy
+25 pts 25m
Heaps & Priority Queues medium

Top K Frequent Elements

Given an integer array and a number k, return the k most frequent elements using a heap-based approach.

heap frequency counting
+25 pts 25m
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

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
Matrix & 2D Arrays medium

Number of Islands

Given a 2D grid of '1' (land) and '0' (water), count the number of islands surrounded by water.

matrix graph bfs
+25 pts 30m
Matrix & 2D Arrays medium

Number of Islands in a Matrix

Count the number of distinct islands (connected groups of 1s) in a 2D binary matrix.

matrix dfs bfs
+20 pts 20m
Matrix & 2D Arrays medium

Regions Cut by Slashes

Given a grid of slashes, count the number of connected regions formed by the slashes and the grid borders.

grid dfs union-find
+30 pts 30m
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
Datetime & Time Calculations easy

Days Between Dates

Write a function that returns the number of days between two given dates.

datetime date-arithmetic calendar
+10 pts 15m
Datetime & Time Calculations easy

Add Days to Date

Given a date in YYYY-MM-DD format and an integer number of days, return the resulting date in the same format.

datetime date arithmetic
+8 pts 10m
Datetime & Time Calculations easy

Business days between

Calculate the number of business days (Mon-Fri) between two dates, inclusive of both endpoints.

datetime weekdays date-arithmetic
+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
Datetime & Time Calculations easy

Duration Human Readable

Write a function that turns a number of seconds into a human-readable duration like '2 hours, 1 minute'.

datetime strings formatting
+10 pts 15m
Datetime & Time Calculations medium

Julian Day Number Converter

Implement two functions to convert between Gregorian calendar dates and Julian Day Numbers using a standard formula.

datetime date-arithmetic algorithms
+20 pts 20m
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

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