Senior Developer Interview
Programming exercise
Count conversions by campaign
Build a function that takes a list of conversion events and returns the number of valid conversions per campaign. You have 45 minutes and may consult documentation. Write and run your code in your own editor, then paste it below.
- An event is valid if it has an
eventIdand acampaignIdthat are both strings and neither is empty or whitespace-only. Keep valid IDs exactly as supplied. - Count each valid
eventIdonce across the entire list. The first valid occurrence wins, even if another occurrence has a different campaign. - Report how many events were invalid. Valid duplicates do not increase that count.
- Support up to one million events.
Example input
[
{"eventId": "e1", "campaignId": "A"},
{"eventId": "e2", "campaignId": "B"},
{"eventId": "e1", "campaignId": "B"},
{"eventId": "e3", "campaignId": ""},
{"eventId": "e3", "campaignId": "A"}
]
Expected result
{"counts": {"A": 2, "B": 1}, "invalidCount": 1}
Submission
OpenAI review
Rubric-based feedback from reading the answer. Confirm correctness by having the candidate run the tests and explain the solution.