Meta software engineer interviews cover algorithms, data structures, system design, and coding problems drawn from real interview rounds.
No verified questions yet for Meta.
WhatsAppMailbox class for direct messages. Each recipient has an independent sequence starting at 1. Every new message for that recipient receives the next sequence number, regardless of its sender.(sender_id, request_id). Retrying with the same recipient and text returns the original sequence number without creating another message, even if the original was acknowledged. Reusing that key with a different recipient or text raises ValueError without changing state.poll returns up to limit unacknowledged messages in ascending sequence order. Polling does not remove messages: consecutive polls without an acknowledgment return the same prefix. Track the highest sequence ever returned by a poll for each recipient.acknowledge cumulatively removes all messages through the supplied sequence. The sequence must be between 0 and that recipient's highest-ever-polled sequence, inclusive; otherwise raise ValueError without changing state. Valid acknowledgments at or below the already-acknowledged sequence are no-ops. Return the number of newly removed messages.unread_count returns the number of unacknowledged messages, including messages already polled. Unknown users have empty mailboxes, a highest-ever-polled sequence of 0, and an unread count of 0. Returned messages must be immutable so callers cannot modify stored message data.Class APIWhatsAppMailbox() — Construct an empty service.send(sender_id: str, recipient_id: str, request_id: str, text: str) -> int — Enqueue a new message or return the sequence from an identical retry.poll(recipient_id: str, limit: int) -> list[Message] — Return the earliest pending messages; raise ValueError unless 1 <= limit <= 100.acknowledge(recipient_id: str, through_sequence: int) -> int — Cumulatively acknowledge messages, subject to the delivery bound above.unread_count(recipient_id: str) -> int — Return the current pending-message count.Message — An immutable record with sequence: int, sender_id: str, recipient_id: str, and text: str.[
{"method":"send","args":["alice","bob","req-1","Hi"]},
{"method":"send","args":["alice","bob","req-1","Hi"]},
{"method":"send","args":["carol","bob","req-1","Hello"]},
{"method":"poll","args":["bob",1]},
{"method":"poll","args":["bob",1]},
{"method":"acknowledge","args":["bob",1]},
{"method":"poll","args":["bob",10]},
{"method":"unread_count","args":["bob"]}
][
1,
1,
2,
[{"sequence":1,"sender_id":"alice","recipient_id":"bob","text":"Hi"}],
[{"sequence":1,"sender_id":"alice","recipient_id":"bob","text":"Hi"}],
1,
[{"sequence":2,"sender_id":"carol","recipient_id":"bob","text":"Hello"}],
1
]1 twice. Acknowledging it leaves only sequence 2 pending.Example 2:[
{"method":"send","args":["alice","bob","r1","Hi"]},
{"method":"acknowledge","args":["bob",1]},
{"method":"poll","args":["bob",10]},
{"method":"acknowledge","args":["bob",1]},
{"method":"send","args":["alice","bob","r1","Hi"]},
{"method":"send","args":["alice","bob","r1","Changed"]},
{"method":"acknowledge","args":["bob",1]},
{"method":"unread_count","args":["bob"]}
]ValueError as an error object and continues:[
1,
{"error":"ValueError"},
[{"sequence":1,"sender_id":"alice","recipient_id":"bob","text":"Hi"}],
1,
1,
{"error":"ValueError"},
0,
0
]1 removes one message. Retrying the original send returns 1 without restoring that message, and changing its text is rejected.Constraints100,000 method calls and 10,000 distinct users per service instance. IDs are nonempty strings of at most 64 characters; text contains 1–4,096 characters.O(1) send and count operations, O(k) polling for k returned messages, and O(r + 1) acknowledgment for r removed messages, excluding string hashing/comparison costs.LRUCache(int capacity): Initializes the cache with a positive size capacity.int get(int key): Returns the value of the key if the key exists, otherwise returns -1.void put(int key, int value): Update the value of the key if present, or add the key-value pair if not existing. When the cache reaches its capacity, it should invalidate the least recently used item before inserting a new item.LRUCache(2); cache.put(1, 1); cache.put(2, 2); cache.get(1); cache.put(3, 3); cache.get(2); cache.put(4, 4); cache.get(1); cache.get(3); cache.get(4);1; -1; 3; 4Constraints:capacity is always positive and will not exceed 1000get and put will always be called with valid keys.Sign up for free to access walkthroughs, AI-generated questions, and more.
Get Started Free