Fibonacci(n)
Return the nth Fibonacci number efficiently.
Run-length encoding
Compress consecutive identical characters, e.g. 'aaabbc' → 'a3b2c1'.
Longest common prefix
Find the longest common prefix among a list of strings.
Integer to Roman
Convert a positive integer to its Roman numeral representation.
Zigzag string conversion
Encode a string in zigzag order across numRows rows, then read row by row.
Maximum subarray (Kadane)
Find the contiguous subarray with the largest sum.
Rotate array
Rotate a list right by k positions in place.
Flatten nested list
Yield every integer from an arbitrarily nested list, depth-first.
Merge intervals
Merge all overlapping intervals and return a sorted result.
Product except self
Return an array where output[i] is the product of all elements except nums[i], without using division.
Group anagrams
Group words that are anagrams of each other.
Subarray sum equals K
Count the number of contiguous subarrays whose sum equals k.
Memoize decorator
Implement a @memoize decorator that caches results of a function.
Function composition
Return a function that applies f after g: compose(f, g)(x) == f(g(x)).
Linked list reversal
Implement a singly linked list and a function to reverse it in place.
Matrix addition operator
Implement a Matrix class that supports + and * operators.
Quicksort
Implement quicksort and return a sorted list.
BFS level-order traversal
Return the level-order traversal of a binary tree as a list of lists.
Coin change (DP)
Find the minimum number of coins to make exactly the target amount.
Graph DFS
Return all nodes reachable from a start node via DFS.
Context manager timer
Implement a Timer context manager that records elapsed seconds.
Retry decorator
Implement @retry(times=3) that retries a function on exception.
2D Vector dataclass
Implement a Vector2D dataclass with +, -, scalar *, dot product, and magnitude.
Showing 23 challenges · medium