Meta software engineer interviews cover algorithms, data structures, system design, and coding problems drawn from real interview rounds.
Question Your task is to implement a simple in-memory cloud storage system that maps objects (files) to their metadata (name, size, etc.). You...
Input: Graph (nodes and edges)Question Design a banking system that supports account management, transactions, and various financial operations.
Input: Graph (nodes and edges)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: ListQuestion Given a list of strings, find the minimum subset of prefixes that can represent the entire input set. A string is "represented" if it...
Input: Array of stringsShortest 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...
Description Implement a simplified in-memory database that supports record manipulation with various operations. The system should handle basic...
Input: Graph (nodes and edges)Question Given an array of integers numbers, count all elements that are not equal to numbers[0] or numbers[1] (if those indices exist in the...
Question You are given a string text consisting of unique lowercase English words separated by spaces. For each word, compute the absolute...
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)Question You are monitoring the building density in a district of houses. The district is represented as a number line, where each house is located...
Input: Array of integerslocations representing the...Input: Array of integers+ and -, and parentheses ( and ), simplify...Input: StringMinimum Sum Tree Path
Input: Binary treeScenario
Part 1 — Default delivery safeguards
id, timestamp, tenant, sender, recipient, campaign, and bytes. timestamp is an integer number of seconds and bytes is the nonnegative payload size, both encoded as strings.timestamp order, breaking ties by ascending ASCII id. Return decisions in that order, regardless of input order.payload_size: a message may contain at most 1000 bytes.sender_rate: each (tenant, sender) may admit at most 3 messages in a rolling 60-second window.recipient_rate: each (tenant, recipient) may admit at most 2 messages in a rolling 60-second window.t, a window of width w contains previously admitted messages with timestamps in (t - w, t], plus the current message when calculating projected usage. Earlier processed messages at the same timestamp count.id, status (ADMITTED or REJECTED), and violations.evaluate_messages(messages: list[dict[str, str]]) -> candidate_definedExample 1:
{
"messages": [
{"id":"m1","timestamp":"0","tenant":"T","sender":"a","recipient":"x","campaign":"C","bytes":"400"},
{"id":"m2","timestamp":"1","tenant":"T","sender":"a","recipient":"x","campaign":"C","bytes":"600"},
{"id":"m3","timestamp":"2","tenant":"T","sender":"a","recipient":"x","campaign":"C","bytes":"100"},
{"id":"m4","timestamp":"3","tenant":"T","sender":"a","recipient":"y","campaign":"C","bytes":"1000"},
{"id":"m5","timestamp":"4","tenant":"T","sender":"a","recipient":"z","campaign":"C","bytes":"100"},
{"id":"m6","timestamp":"5","tenant":"T","sender":"b","recipient":"z","campaign":"C","bytes":"1001"}
]
}[
{"id":"m1","status":"ADMITTED","violations":[]},
{"id":"m2","status":"ADMITTED","violations":[]},
{"id":"m3","status":"REJECTED","violations":["recipient_rate"]},
{"id":"m4","status":"ADMITTED","violations":[]},
{"id":"m5","status":"REJECTED","violations":["sender_rate"]},
{"id":"m6","status":"REJECTED","violations":["payload_size"]}
]m3 would be the third admitted message to recipient x, exceeding 2. Because it is rejected, m4 becomes sender a's third admitted message and is allowed, including its exactly-1000-byte payload. m5 would be sender a's fourth message. m6 exceeds the payload limit by 1 byte.Part 2 — Configurable overlapping budgets
extra_rules, a list of maps whose keys and values are strings. Each map contains id, group_by, metric, window_seconds, and limit.group_by is a comma-separated list of distinct fields chosen from tenant, sender, recipient, and campaign, with no whitespace. All fields together form the rule's grouping key.metric is either messages, contributing 1 per admitted message, or bytes, contributing the message's payload size. window_seconds is a positive integer string; limit is a nonnegative integer string.rule, numeric projected, and numeric limit, sorted by rule ID. For payload_size, projected usage is simply the current payload size.admitted_totals containing numeric messages and bytes. These totals include all admitted messages in the batch, even if their rolling-window entries later expire.decisions and admitted_totals; an equivalent typed representation is acceptable.evaluate_with_rules(messages: list[dict[str, str]], extra_rules: list[dict[str, str]]) -> candidate_definedExample 2:
{
"messages": [
{"id":"m1","timestamp":"0","tenant":"T","sender":"a","recipient":"x","campaign":"C","bytes":"700"},
{"id":"m2","timestamp":"10","tenant":"T","sender":"b","recipient":"y","campaign":"C","bytes":"600"},
{"id":"m3","timestamp":"20","tenant":"T","sender":"c","recipient":"z","campaign":"C","bytes":"300"},
{"id":"m4","timestamp":"30","tenant":"T","sender":"c","recipient":"z","campaign":"D","bytes":"200"},
{"id":"m5","timestamp":"60","tenant":"T","sender":"d","recipient":"w","campaign":"C","bytes":"700"}
],
"extra_rules": [
{"id":"tenant_bytes","group_by":"tenant","metric":"bytes","window_seconds":"60","limit":"1500"},
{"id":"campaign_cap","group_by":"tenant,campaign","metric":"messages","window_seconds":"30","limit":"2"}
]
}{
"decisions": [
{"id":"m1","status":"ADMITTED","violations":[]},
{"id":"m2","status":"ADMITTED","violations":[]},
{"id":"m3","status":"REJECTED","violations":[
{"rule":"campaign_cap","projected":3,"limit":2},
{"rule":"tenant_bytes","projected":1600,"limit":1500}
]},
{"id":"m4","status":"ADMITTED","violations":[]},
{"id":"m5","status":"ADMITTED","violations":[]}
],
"admitted_totals":{"messages":4,"bytes":2200}
}m2, tenant usage is 700 + 600 = 1300 bytes and campaign C has 2 messages. m3 projects 1300 + 300 = 1600 bytes and 3 campaign messages, so both extra rules fire and neither budget changes. m4 belongs to campaign D and raises tenant usage to exactly 1300 + 200 = 1500. At time 60, m1 is excluded by the open left boundary; m5 projects 600 + 200 + 700 = 1500 tenant bytes. Campaign C has no prior admitted message in (30, 60], so its projected count is 1. Batch totals are 4 messages and 700 + 600 + 200 + 700 = 2200 bytes.Example 3:
{
"messages": [
{"id":"m1","timestamp":"0","tenant":"T","sender":"a","recipient":"x","campaign":"C","bytes":"500"},
{"id":"m2","timestamp":"1","tenant":"T","sender":"a","recipient":"x","campaign":"C","bytes":"500"},
{"id":"m3","timestamp":"2","tenant":"T","sender":"a","recipient":"y","campaign":"D","bytes":"400"},
{"id":"m4","timestamp":"3","tenant":"T","sender":"a","recipient":"x","campaign":"C","bytes":"200"},
{"id":"m5","timestamp":"60","tenant":"T","sender":"a","recipient":"x","campaign":"C","bytes":"600"}
],
"extra_rules": [
{"id":"tenant_bytes","group_by":"tenant","metric":"bytes","window_seconds":"60","limit":"1500"},
{"id":"campaign_cap","group_by":"tenant,campaign","metric":"messages","window_seconds":"30","limit":"2"}
]
}{
"decisions": [
{"id":"m1","status":"ADMITTED","violations":[]},
{"id":"m2","status":"ADMITTED","violations":[]},
{"id":"m3","status":"ADMITTED","violations":[]},
{"id":"m4","status":"REJECTED","violations":[
{"rule":"campaign_cap","projected":3,"limit":2},
{"rule":"recipient_rate","projected":3,"limit":2},
{"rule":"sender_rate","projected":4,"limit":3},
{"rule":"tenant_bytes","projected":1600,"limit":1500}
]},
{"id":"m5","status":"ADMITTED","violations":[]}
],
"admitted_totals":{"messages":4,"bytes":2000}
}m4, the tenant has 500 + 500 + 400 = 1400 admitted bytes, sender a has 3 admitted messages, recipient x has 2, and campaign C has 2. Therefore m4 simultaneously projects 1600 bytes, 4 sender messages, 3 recipient messages, and 3 campaign messages. At time 60, m1 expires from the 60-second windows and both earlier campaign C messages have expired from its 30-second window. m5 projects 500 + 400 + 600 = 1500 tenant bytes, 3 sender messages, 2 recipient messages, and 1 campaign message, so it is admitted. Batch totals are 4 messages and 500 + 500 + 400 + 600 = 2000 bytes.Notes:
n, 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.serialize and deserialize that convert a binary tree into a single string representation and back again. The representation must be unique and should correctly reconstruct the original tree structure. You can use any traversal method. def serialize(root: Optional[TreeNode]) -> str: def deserialize(data: str) -> Optional[TreeNode]: root = [1,2,3,null,null,4,5] "1,2,3,null,null,4,5" root = [1] "1,null" 0 and 10^4 nodes. [-1000, 1000]. 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^9start to node end.Example 1:edges = [[0, 1], [1, 2], [2, 3]], start = 0, end = 3[0, 1, 2, 3]0 to node 3 is 0 -> 1 -> 2 -> 3.Example 2:edges = [[0, 1], [1, 2], [0, 2], [2, 3]], start = 0, end = 3[0, 2, 3]Constraints:1 <= edges.length <= 10^4s, find the length of the longest substring containing at most two distinct characters.Example 1:s = "eceba"33.Example 2:s = "ccaabbb"55.Constraints:1 <= s.length <= 10^5s consists of English letters, digits, symbols, and spaces.Sign up for free to access walkthroughs, AI-generated questions, and more.
Get Started Free