Reference10 Interactive Drills

Muscle Memory Drills

These are the patterns that should become automatic. Practice typing them from memory until you can hit the time targets. Each drill includes an interactive code editor with real test execution - your code runs against actual tests to verify correctness.

How to Practice

1

Read

Read the prompt and understand what you need to build

2

Type

Type your solution in the editor - timer starts on first keystroke

3

Run

Click 'Run Tests' to execute your code against real tests

4

Repeat

Use hints if stuck, then reset and try again faster

1

FastAPI GET Endpoint

0:00 / 3:00

Create a GET endpoint with path parameters that returns JSON

Your Task
Create a FastAPI GET endpoint at "/users/{user_id}" that:
1. Accepts a user_id as a path parameter (integer)
2. Returns a JSON object with: {"user_id": <the id>, "name": "User <id>", "active": true}

Example: GET /users/42 should return {"user_id": 42, "name": "User 42", "active": true}
2

FastAPI POST with Pydantic

0:00 / 4:00

Create a POST endpoint with Pydantic model validation

Your Task
Create a FastAPI POST endpoint at "/items" that:
1. Accepts a JSON body with: name (string), price (float), quantity (int, optional, default 1)
2. Uses a Pydantic model called "Item" for validation
3. Returns the item with an added "total" field (price * quantity)

Example: POST {"name": "Widget", "price": 9.99, "quantity": 3}
Returns: {"name": "Widget", "price": 9.99, "quantity": 3, "total": 29.97}
3

SQLAlchemy Model + CRUD

0:00 / 5:00

Create a Task model with create and get operations

Your Task
Create a SQLAlchemy model and CRUD operations:

1. Define a "Task" model with columns:
   - id: Integer, primary key, autoincrement
   - title: String(100), not nullable
   - completed: Boolean, default False

2. Create functions:
   - create_task(db: Session, title: str) -> Task
   - get_task(db: Session, task_id: int) -> Task | None

The database setup is provided. Focus on the model and CRUD functions.
4

React Fetch + Display

0:00 / 4:00

Fetch data with useEffect and display as a list

Your Task
Create a React component "UserList" that:

1. Uses useState to store an array of users
2. Uses useEffect to fetch from "/api/users" on mount
3. Displays users in a <ul> with each user's name in an <li>
4. Each <li> should have key={user.id}

Assume the API returns: [{ id: 1, name: "Alice" }, { id: 2, name: "Bob" }]
5

React Form Submission

0:00 / 5:00

Controlled input with POST request and state update

Your Task
Create a React component "AddTodo" that:

1. Has a controlled text input for the todo title
2. Has a submit button
3. On submit: POST to "/api/todos" with { title: inputValue }
4. After successful POST, add the returned todo to a todos array in state
5. Display the todos list below the form

Assume POST returns the created todo: { id: 1, title: "...", completed: false }
6

Loading + Error States

0:00 / 4:00

Implement the three states pattern: loading, error, success

Your Task
Create a React component "DataFetcher" that:

1. Has three states: loading (boolean), error (string | null), data (any | null)
2. Fetches from "/api/data" on mount
3. Shows "Loading..." while fetching
4. Shows error message if fetch fails
5. Shows the data (as JSON string) when successful

Handle the fetch error with try/catch and set appropriate states.
7

CORS Setup

0:00 / 3:00

Configure FastAPI CORS middleware

Your Task
Configure CORS middleware for a FastAPI app:

1. Import CORSMiddleware from fastapi.middleware.cors
2. Add middleware with:
   - allow_origins: ["http://localhost:3000"]
   - allow_credentials: True
   - allow_methods: ["*"]
   - allow_headers: ["*"]

3. Create a test endpoint GET /health that returns {"status": "ok"}
8

useEffect Cleanup

0:00 / 3:00

Implement setInterval with proper cleanup on unmount

Your Task
Create a React component "Timer" that:

1. Uses useState to track elapsed seconds (starts at 0)
2. Uses useEffect with setInterval to increment every 1000ms
3. Returns a cleanup function that calls clearInterval
4. Displays: "Elapsed: X seconds"

This prevents memory leaks when the component unmounts.
9

Optimistic UI Update

0:00 / 5:00

Update UI immediately with rollback on failure

Your Task
Create a React component "LikeButton" that:

1. Shows current like count from props.initialCount
2. On click: immediately increment the count (optimistic update)
3. Send POST to "/api/like"
4. If POST fails: roll back to previous count
5. Show the count in a button: "Like ({count})"

The optimistic pattern: save old state, update UI, then rollback if API fails.
10

WebSocket Echo Server

0:00 / 4:00

Create a FastAPI WebSocket endpoint that echoes messages

Your Task
Create a FastAPI WebSocket endpoint at "/ws" that:

1. Accepts WebSocket connections
2. Sends a welcome message: "Connected!"
3. Continuously receives messages and echoes them back with "Echo: " prefix
4. Handles disconnection gracefully

Example: Client sends "hello" -> Server responds "Echo: hello"

Tips for Building Muscle Memory

  • Practice in short bursts (15-20 minutes) rather than long sessions
  • Focus on accuracy first, then speed - sloppy practice builds sloppy habits
  • Use hints sparingly - try at least once without them first
  • Say the code out loud as you type it to engage more of your brain
  • If you get stuck on the same part repeatedly, isolate and drill just that part
  • Track your times - seeing improvement is motivating

Code Execution Requirement

These interactive drills require Judge0 to execute your code. If you see connection errors when running tests, make sure Judge0 is running locally or that the JUDGE0_API_URL environment variable is configured correctly.