Replay Connection Request Events Through a State Machine

Last updated: November 29, 2026

Quick Overview

Process an ordered log of events (send, accept, ignore, withdraw) between sender and recipient pairs and return the final state of each pair plus the number of events that were invalid for the pair's current state.

LinkedIn
Coding & Algorithms
Software Engineer
LinkedIn
November 29, 2026
Software Engineer
Phone Screen
Coding & Algorithms
Easy

0

0

0 solved


Process an ordered log of events (send, accept, ignore, withdraw) between sender and recipient pairs and return the final state of each pair plus the number of events that were invalid for the pair's current state.

Invitations are the core growth loop at LinkedIn, and their lifecycle is a small state machine. The interviewer checks that you encode transitions as data rather than nested ifs and that you make the invalid-transition rule explicit.

What the Interviewer Expects
  • Lists states and allowed transitions before coding
  • Encodes transitions as a lookup table keyed by (state, event)
  • Keys pairs by (sender, recipient) and defaults to NONE
  • Counts invalid events without changing state
  • Mentions how a resend after withdraw or ignore should behave
Key Topics to Cover
state machine
simulation
hash map
event processing
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
  • How would you enforce a cooldown before a resend after withdraw?
  • How do you handle out-of-order events from different services?
  • What would you store so the history is auditable?
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Practice DSA Problems
Sample Answer
Requirements

States: NONE, PENDING, CONNECTED, IGNORED. Events: send (NONE, IGNORED to PENDING; a withdrawn invite returns to NONE so it can be re-sent), accept (PENDING to CONNECTED), ignore (PENDING to IGN...

High-Level Design

A transition table {(state, event): next_state} makes the rules reviewable and testable on their own. The replay loop is then three lines: look up the current state (default NONE), check the table, ...


Submit Your Answer
Markdown supported