Meta software engineer interviews cover algorithms, data structures, system design, and coding problems drawn from real interview rounds.
Question Given a list of ages representing users in a social network, calculate the total number of friend requests each user will send based on...
Input: ListShortest Substring with N Unique Characters *This is a variation of the leetcode problem* Given a string s and an integer n, find the length of...
Question In a highly automated warehouse, a robot organizes packages stored in a rectangular grid. The grid is represented as a 2D list of integers...
Input: Matrix (2D array)locations representing the...Input: Array of integersMinimum Sum Tree Path
Input: Binary treeTips For AI Coding Rounds AI coding rounds are not as different from regular coding rounds as you might think. The interviewer still needs to get...
Input: Given inputn, return the number of unique Binary Search Trees (BST) that can be formed using n distinct integers from 1 to n. A Binary Search Tree is defined as a tree in which all nodes follow the left < current < right property.def numTrees(n: int) -> int:n = 3 5 n = 1 1 1 <= n <= 19serialize function should convert the tree into a string form, so it can be easily saved or transmitted. The deserialize function should take this string and reconstruct the binary tree. Use pre-order traversal for serialization and handle null values appropriately.def serialize(root: Optional[TreeNode]) -> str: def deserialize(data: str) -> Optional[TreeNode]:root = [1,2,3,null,null,4,5] "1,2,#,#,3,4,#,#,5,#,#" data = "1,2,#,#,3,4,#,#,5,#,#" root = [1,2,3,null,null,4,5] [0, 10^4]. [-10^4, 10^4].events, where each event is represented as a pair of integers [start, end]. An individual can attend an event if they can arrive at the event's start time or after the event has started. Each event must be completed to move to the next one. Your task is to return the maximum number of events that can be attended. def max_events(events: List[List[int]]) -> int:events = [[1,2],[2,3],[3,4]] 3 events = [[1,4],[4,6],[6,8],[3,5]] 4 1 <= len(events) <= 10^41 <= start <= end <= 10^5nums of size n, return all the unique triplets [nums[i], nums[j], nums[k]] such that i, j, and k are different indices, and their sum equals to zero. The result must not include duplicate triplets, hence the order of results does not matter.Function/class signature:def three_sum(nums: List[int]) -> List[List[int]]:nums = [-1, 0, 1, 2, -1, -4] [[-1, -1, 2], [-1, 0, 1]] nums = [] [] 0 <= n <= 3000 -10^5 <= nums[i] <= 10^5def level_order_sorted_messages(root: Optional[TreeNode]) -> List[Tuple[str, int]]: root - a tree with nodes representing messages sent by different users at various timestamps [("Alice", 1), ("Bob", 2), ("Charlie", 3)] [("David", 4), ("Eve", 5), ("Frank", 7)] 10^4 nodes. 100 characters long.user_ids and a target_sum, return the indices of the two user IDs such that their corresponding values add up to the target_sum. You may assume that each input would have exactly one solution, and you may not use the same element twice.def find_complementary_pair(user_ids: List[int], target_sum: int) -> List[int]:user_ids = [3, 5, 2, 8, 6], target_sum = 10 [0, 3] 3 and 8 add up to 10.user_ids = [1, 4, 5, 6, 7], target_sum = 11 [2, 3] 5 and 6 add up to 11.2 <= len(user_ids) <= 10^4 -10^9 <= user_ids[i] <= 10^9 2 <= target_sum <= 2 * 10^9WhatsAppMailbox 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.Sign up for free to access walkthroughs, AI-generated questions, and more.
Get Started Free