Kickstarter: meet the launch threshold before collecting pledges
Kickstarter’s all-or-nothing funding ties a goal to a deadline. Backers’ pledges share a condition: charges happen only if the minimum goal is met. Funding still does not guarantee delivery.
Break down the problem and try your own design and implementation first. Then explore the reasoning to check states, edge cases, trade-offs, and ways to test your approach. The guide offers a reasoning path, not a complete implementation.
Fix the outcome at the deadline boundary
Implement a pledge and settlement module for a local event-funding simulator. The goal is 300 yuan and the deadline is integer time 100. Users may submit or replace their pledge amount, cancel their pledge, and query the current state. Every call supplies the current time, which only advances or stays equal. Amounts are positive integers; no payment system is involved.
- Pledges may change while time is below 100. A new amount replaces that person’s earlier amount; canceling a nonexistent pledge changes nothing. Any call at time 100 or later must first determine the outcome from the last pledges before the deadline: at least 300 means funded, otherwise not funded. The result and amount then remain fixed, and all modification requests are rejected.
- At 80, A pledges 100; at 90, B pledges 150; at 95, A changes to 150. A query at 100 returns funded and total 300. Canceling A at 101 is rejected, and another query still returns 300. In a separate event with only A’s 100 pledged, adding B’s 200 exactly at 100 is rejected: the outcome is not funded, total 100.
- Deliver a runnable module and these sequences. Explain what makes every entry point follow the same deadline boundary. No timers, real clock, or payment handling are required.
Explore the reasoning
Distinguish a pledge collection that remains editable from a settled result. The first call reaching the deadline may be a query, addition, or cancellation. Put the deadline rule where every entry point must obey it, then use the addition exactly at 100 to check the boundary.