← Back to leaderboard

gemma4:e2b Champion

1.8 GB measured VRAM · sub-4GB tier
Tier 1 — floor 5/5
seed 1 (passed): all cases passed
1133 tokens · 13.12s
extracted code
import re

def is_palindrome(s: str) -> bool:
    """
    Checks if a string is a palindrome, ignoring case, spaces, and punctuation.

    Args:
        s: The input string to check.

    Returns:
        True if the string is a palindrome, False otherwise.
    """
    # 1. Preprocessing: Filter the string to keep only alphanumeric characters
    # and convert them to lowercase.
    
    # We use a generator expression and join for efficiency.
    cleaned_chars = [char.lower() for char in s if char.isalnum()]
    cleaned_s = "".join(cleaned_chars)
    
    # 2. Palindrome Check: Compare the cleaned string with its reverse.
    # Slicing [::-1] is a Pythonic way to reverse a sequence.
    return cleaned_s == cleaned_s[::-1]

# --- Examples ---

# Example 1: Classic palindrome (True)
test1 = "A man, a plan, a canal: Panama"
print(f"'{test1}' is a palindrome: {is_palindrome(test1)}")  # Output: True

# Example 2: Simple palindrome (True)
test2 = "racecar"
print(f"'{test2}' is a palindrome: {is_palindrome(test2)}")    # Output: True

# Example 3: Not a palindrome (False)
test3 = "hello world"
print(f"'{test3}' is a palindrome: {is_palindrome(test3)}")    # Output: False

# Example 4: P
... [truncated, 148 more chars]
Tier 2 — edge-case handling 5/5
seed 1 (passed): all cases passed
1764 tokens · 9.069s
extracted code
def find_second_largest_unique(data: list[int]) -> int | None:
    """
    Finds the second largest unique value in a list of integers.

    Args:
        data: A list of integers.

    Returns:
        The second largest unique integer, or None if there are fewer 
        than two unique elements.
    """
    if not data:
        # Edge case 1: Empty list
        return None

    # Step 1: Find all unique values using a set
    unique_values = set(data)

    # Step 2: Check if there are at least two unique values
    if len(unique_values) < 2:
        # Edge case 2 & 3: List has 0 or 1 unique element (e.g., [5] or [])
        return None

    # Step 3: Convert the set back to a list and sort it in descending order
    # Sorting is necessary to easily identify the largest and second largest.
    sorted_unique = sorted(list(unique_values), reverse=True)

    # Step 4: The second largest unique value will be at index 1
    return sorted_unique[1]

# --- Examples and Edge Case Testing ---

print("--- Test Cases ---")

# 1. Standard case (Duplicates present)
list1 = [10, 5, 20, 20, 3]
result1 = find_second_largest_unique(list1)
# Unique values: {3, 5, 10, 20}. Sorted: [20, 10, 5, 3]. S
... [truncated, 1279 more chars]
Tier 3 — multi-class interface 5/5
seed 1 (passed): all cases passed
1811 tokens · 9.682s
extracted code
class Book:
    """Represents a single book with its details and availability status."""
    def __init__(self, title, author, isbn):
        self.title = title
        self.author = author
        self.isbn = isbn
        # Default state: the book is available when added
        self.available = True

    def __str__(self):
        """Provides a readable string representation of the Book object."""
        status = "Available" if self.available else "Checked Out"
        return f"Title: {self.title}, Author: {self.author}, ISBN: {self.isbn} | Status: {status}"

class Library:
    """Manages a collection of books and handles checkout/return operations."""
    def __init__(self):
        # Use a dictionary to store books, keyed by ISBN for fast lookup
        self._books = {}

    def add_book(self, book):
        """Adds a Book object to the library inventory."""
        if book.isbn in self._books:
            print(f"Error: Book with ISBN {book.isbn} already exists.")
            return
        self._books[book.isbn] = book
        print(f"Successfully added book: '{book.title}' to the library.")

    def checkout_book(self, isbn):
        """Marks a book as checked out."""
     
... [truncated, 3013 more chars]
Tier 4 — bug-fix 5/5
seed 1 (passed): all cases passed
1288 tokens · 6.845s
extracted code
def apply_discount(price, discount_percent):
    """
    Applies a percentage discount to a price.
    discount_percent is 0-100 (e.g., 20 means 20% off).
    Returns the discounted price, rounded to 2 decimal places.
    Raises ValueError if discount_percent is negative or greater than 100.
    Raises ValueError if price is negative.
    """
    # Input validation for price
    if price < 0:
        raise ValueError("Price cannot be negative.")

    # Input validation for discount_percent
    if not (0 <= discount_percent <= 100):
        raise ValueError("Discount percentage must be between 0 and 100.")

    # Calculate the discounted price
    # The discount amount is calculated by dividing the percentage by 100.
    discount_factor = discount_percent / 100
    new_price = price * (1 - discount_factor)

    # Return the result rounded to 2 decimal places
    return round(new_price, 2)
Tier 5 — schema cross-reference 5/5
seed 1 (passed): all cases passed
2170 tokens · 11.106s
extracted code
from collections import defaultdict

def top_customers(orders: list[dict], customers: list[dict], n: int) -> list[dict]:
    """
    Returns the top n customers by total order amount.

    Args:
        orders: List of order dictionaries (order_id, customer_id, amount).
        customers: List of customer dictionaries (customer_id, name).
        n: The number of top customers to return.

    Returns:
        A list of dictionaries, each containing 'name', 'total_spent', and 'order_count', 
        sorted descending by total_spent.
    """
    
    # Step 1: Create a lookup map for customer names (for O(1) access)
    customer_map = {cust['customer_id']: cust['name'] for cust in customers}

    # Step 2: Aggregate data from orders
    # We use defaultdict to easily store total spending and order counts per customer.
    customer_stats = defaultdict(lambda: {
        'total_spent': 0.0,
        'order_count': 0
    })

    for order in orders:
        customer_id = order['customer_id']
        amount = order['amount']
        
        # Ensure the customer exists in our tracking structure (it should, based on input constraints)
        if customer_id in customer_map:
            sta
... [truncated, 1585 more chars]
Tier 6 — strict JSON format 5/5
seed 1 (passed): strict JSON, all values correct
824 tokens · 4.395s
raw response
{"low_stock_items": ["Widget", "Gizmo"], "total_value": 289.85, "most_expensive_item": "Gizmo"}