OpenBook
  • Problems
  • Tracks
  • How it works
  • Pricing
Start practicingSign In
Problems/CRUD & REST

21. Polls with One Vote per User

Easy

Create polls with an optional closing time, let each user cast one vote they can change while the poll is open, and count the results.

30 minute budget0.0% acceptanceCRUD · voting · time

Requirements

  1. 01POST /polls takes { question, options, closesAt? } and returns 201 with the poll; each option gets an id. Invalid input is a 400 with { error }.
  2. 02POST /polls/:id/votes { optionId } records the vote of the user named in the x-user header: 201 for a first vote, 200 when it replaces that user's earlier vote. A missing x-user is a 401, an unknown optionId a 400, an unknown poll a 404.
  3. 03Each user has one vote per poll and may change it while the poll is open; a poll with no closesAt stays open.
  4. 04GET /polls/:id/results returns { pollId, closed, totalVotes, options: [{ id, text, votes }], winners } with every option in creation order.
  5. 05Time comes from the x-now header (ISO date) when present, otherwise the real clock.

What the hidden tests check

  • Everything the interviewer tells you is checked.
  • Each test creates its own polls and controls the clock with x-now.

4 more details are held back. In a mock interview they come out only when you ask the interviewer the right question; in practice they are listed in the workspace.

Sign in to start

Attempts, files and transcripts are saved to your account so the grader can review how you worked.

Sign inCreate an account
OpenBook

Practice for interviews where you build a feature with an AI assistant.

Early preview. Problems, grading and the interviewer are still changing.

Practice

  • Problems
  • Tracks
  • How it works
  • Pricing

Legal

  • Terms
  • Privacy
© 2026 OpenBook.