Coding Benchmark
Source: Adapted from HumanEval (MIT), SWE-bench (MIT), and MT-Bench coding (Apache 2.0) evaluation styles. 25 prompts, single-turn webhook format. · 25 prompts
Prompts
Write a Python function `is_palindrome(s: str) -> bool` that returns True if the string is a palindrome, ignoring case and non-alphanumeric characters. Include test cases.
Write a Python function `two_sum(nums: list[int], target: int) -> list[int]` that returns the indices of two numbers that add up to the target. Explain your approach and time compl…
Write a Python function `longest_substring_without_repeating(s: str) -> int` that returns the length of the longest substring without repeating characters. Provide the sliding-wind…
Write a Python function `merge_intervals(intervals: list[list[int]]) -> list[list[int]]` that merges all overlapping intervals. Include edge case handling.
Write a Python function `binary_search(arr: list[int], target: int) -> int` that returns the index of target in a sorted array, or -1 if not found. Implement both iterative and rec…
Design a URL shortener service. Describe the API endpoints, database schema, and how you'd handle collisions. Include a Python implementation of the core encoding function.
Design a rate limiter for a REST API. Explain the token bucket and sliding window algorithms, then implement a sliding-window rate limiter in Python with a Redis-like interface.
Design a simple key-value store with TTL support. Write the core Python class with `get`, `set`, `delete`, and TTL expiration logic. Discuss tradeoffs between sorted expiration and…
The following Python function attempts to find the most frequent element in a list. Find and fix all bugs, then explain what was wrong: ```python def most_frequent(items): cou…
Review this Python code for thread safety issues and rewrite it to be thread-safe: ```python class Counter: def __init__(self): self._count = 0 def increment(self)…
This SQL query is slow on a table with 10 million rows. Identify the performance issue and rewrite it: ```sql SELECT user_id, COUNT(*) as order_count FROM orders WHERE YEAR(create…
Write a Python async function using `aiohttp` that fetches data from 3 different APIs concurrently, merges the results by a common key, and returns the combined dataset. Handle tim…
Write a Python decorator `@retry(max_attempts=3, backoff=2.0)` that retries a function on exception with exponential backoff. Include logging of each retry attempt.
Write a FastAPI endpoint `POST /users` with Pydantic validation, password hashing, and SQLAlchemy database insertion. Include proper error handling and HTTP status codes.
Write a Python script that reads a large CSV file (10GB) in chunks, filters rows by a date column, aggregates by category, and writes the result to a new CSV. Explain how you handl…
Write a SQL query to find the top 3 highest-paid employees in each department from tables `employees(id, name, salary, department_id)` and `departments(id, name)`. Include the depa…
Given a table `transactions(id, user_id, amount, created_at)`, write a SQL query that computes a 7-day moving average of daily transaction totals for each user.
Write a Python function using SQLAlchemy ORM that performs a bulk upsert - inserting new rows and updating existing ones based on a unique constraint. Explain when to use ORM vs. r…
Write unit tests for a `ShoppingCart` class with methods `add_item`, `remove_item`, `apply_discount`, and `checkout`. Use pytest. Cover edge cases including empty cart, invalid dis…
Write a Python function `slugify(title: str) -> str` that converts a string to a URL-safe slug. Then write property-based tests using `hypothesis` to verify invariants (e.g., no up…
Write a Dockerfile for a Python FastAPI application with multi-stage builds, non-root user, health check, and proper layer caching. Explain each stage's purpose.
Write a GitHub Actions workflow that runs linting, type checking, unit tests, and builds a Docker image on every pull request. Explain caching strategies to keep CI fast.
Write a TypeScript generic type `DeepReadonly<T>` that makes all nested properties of T readonly. Include usage examples and explain how it handles arrays and objects differently.
Write a JavaScript function `debounce(fn, delay)` and `throttle(fn, delay)`. Explain the difference between debouncing and throttling, and when to use each in a frontend applicatio…
Write a Rust function that reads a file line by line, parses each line as JSON, filters by a field value, and writes matching lines to stdout. Handle errors without panicking.