Auditable Election Session
Problem
Design AuditableElectionSession to configure a state, constituency, district, and EVM hierarchy, accept eligible ballots, and report complete constituency totals. Calls operate sequentially on one election session.
Requirements
- Election configuration. A valid district configuration creates missing state and constituency containers, then adds one new district with its EVM candidate sets and eligible voters.
- Ballot acceptance.
castVotereturnstrueand records exactly one vote only when the voter exists, has not voted, the EVM belongs to that voter's district, and the candidate is configured on that EVM. After acceptance, that voter cannot cast another accepted ballot. - Rejected ballots. If any acceptance condition is false,
castVotereturnsfalsewithout changing the voter's eligibility or any candidate total. - Constituency results. A result maps each candidate name to the sum of accepted votes for that name across every EVM in the constituency. It includes every configured candidate, including candidates with zero votes.
API
| Signature | Returns | Behavior |
|---|---|---|
AuditableElectionSession() | Not applicable | Creates an empty election session. |
configureDistrict(stateName: string, constituencyName: string, districtName: string, evmCandidates: map<string, string[]>, eligibleVoterIds: string[]) | Nothing | Adds one valid district aggregate to the hierarchy. |
castVote(voterId: string, evmId: string, candidateName: string) | boolean | Attempts to record the voter's choice and reports whether it was accepted. |
getConstituencyResult(stateName: string, constituencyName: string) | map<string, integer> | Returns the complete aggregate result for an existing constituency. |
Examples
| Step | Operation | Result |
|---|---|---|
| 1 | configureDistrict("North", "River", "Central", {"M1": ["Ada", "Bela"], "M2": ["Ada", "Chen"]}, ["V1", "V2"]) | Nothing |
| 2 | castVote("V1", "M1", "Ada") | true |
| 3 | castVote("V1", "M2", "Chen") | false |
| 4 | castVote("V2", "M2", "Chen") | true |
| 5 | getConstituencyResult("North", "River") | {"Ada": 1, "Bela": 0, "Chen": 1} |
Constraints
- Total configured limits are 100 states, 1000 constituencies, 1000 districts, 10000 EVMs, and 100000 eligible voters, with at least one of each configured entity.
- At most 200000 public method calls occur in one testcase.
- Names and IDs contain 1 to 50 letters, digits, spaces, hyphens, or underscores.
- Each district has at least one EVM and one eligible voter. Each EVM has at least one unique candidate name.
- District paths, EVM IDs, and voter IDs are new when configured. A candidate name may occur on several EVMs in one constituency.
- Result queries identify an existing constituency. Inputs contain no null values.
- Vote totals are nonnegative signed 64-bit integers.
Notes
Map iteration order is not observable. Invalid or conflicting configuration, missing result paths, election phases, ballot replacement, and concurrent use are outside this contract.