Your question is Stream Validation Function. Start with the requirements on the right.
Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.
Alaska Airlines Mileage Plan receives user profile events as an ordered stream. Write a function that accepts valid events while identifying malformed, duplicate, or out-of-order data.
An event is valid when it contains event_id, user_id, email, and occurred_at; both identifiers are non-empty strings; email contains exactly one @ with a non-empty local part and a domain containing a period; and occurred_at is a non-negative integer. An event is also invalid if its event_id was already accepted or if its timestamp is not strictly later than the most recently accepted event for the same user. Rejected events must not update validation state.
Implement process_user_stream(events). The input is a list of dictionaries. Return a dictionary with accepted, the original valid event dictionaries in input order, and rejected_indices, the zero-based indices of invalid events in input order.
Extra fields are allowed and must be preserved. The input stream is already ordered, so do not sort it.
def process_user_stream(events):