HomeChallengesRepsProblemsLeaderboardTake a challenge

The Double Charge

The request timed out, so the phone retried it, so the customer has two identical orders and one of them will be refunded by hand. Make the write safe to repeat.

Beginner15 min on the clock5 graded checks · 100 pointsThe Write Side
Graded by running your code against real cases.

What you build

  • nextId(rows) — the next free id
  • problems(draft) — one message per invalid field, empty when it is fine
  • insert(rows, draft) — append a new row, or refuse and write nothing
  • insertOnce(rows, draft) — the same requestId twice creates one row
  • Never modify the array you were given

Done means

Sending the same order twice leaves one row, and an invalid draft leaves none.

How it is graded

Published in full, before you start — every point is one of these and there is nothing else. Each one runs your code; it is not a search for keywords.

  1. nextId does not collide with an existing id+15Writing a row safely
  2. problems reports every invalid field+20Writing a row safely
  3. insert appends without touching the original+25Writing a row safely
  4. The same requestId twice creates one row+30Safe to repeat
  5. An invalid draft writes nothing at all+10Writing a row safely

What it teaches

Writing a row safelybeginner

Creating a record means deciding its id, checking it before it lands, and never modifying the list you were handed — because a half-written row is harder to find and fix than a rejected request.

Safe to repeatintermediate

A request that times out has not necessarily failed — you just did not hear back — so the client retries, and unless the write recognises that it has already happened the customer is charged twice.

The rest of The Write Side