Bloomberg software engineer interviews cover algorithms, data structures, system design, and coding problems drawn from real interview rounds.
StreamBuffer class that buffers a stream of integer latency samples in FIFO order and supports O(1) access to both the minimum and maximum...Input: Integer(s)Question You are navigating a grid from a start cell S to a destination cell D. Your vehicle has a fuel tank with a maximum capacity. Moving...
Question The Hailstone sequence starts from a positive integer n and repeatedly applies the following rules until reaching 1: - If n is...
Question Design a TradeVolumeTracker class that records trade volumes by ticker symbol and returns an ordered ranking of tickers by volume. The...
Question You are implementing a word filter for a puzzle game. Given a list of candidate words and a set of allowed letters plus one required...
Input: ListQuestion You are given an array of integers and an equivalence function equiv(x, y) that returns true if two values belong to the same group....
Question You are given an N-ary tree where each node has a value and a list of children. Return the 1-indexed level that contains the most nodes....
Input: ListQuestion A string is called uniform if all of its characters appear the same number of times. Given a string s, determine whether it can...
Question Design a StreamPalindrome class that processes a stream of characters one at a time. At any point, it should be able to report whether...
Question You are given an N-ary tree where each node has an integer value. Find the minimum sum path from the root to any leaf node and return that...
Input: Integer(s)Question You are given a list of documents where each document has a name and a body of text. Given a search query word, find and return all...
Input: Listid, trader, desk, city, minute, and amount_usd. Minutes are absolute integer timestamps, not times of day; inputs may be unsorted.AMOUNT_LIMIT: flag an execution when its amount is strictly greater than 1000.00 USD.CITY_CONFLICT: flag an execution if another execution by the same trader occurred in a different city within 60 minutes inclusive, before or after it. Flag both executions in a conflicting pair, even across desks.evaluate_executions(records: list[dict[str, str]]). The concrete return type is up to the candidate; the JSON below defines its observable contents.{"records":[{"id":"a","trader":"u","desk":"A","city":"NYC","minute":"0","amount_usd":"1000.00"},{"id":"b","trader":"u","desk":"A","city":"London","minute":"60","amount_usd":"1000.01"},{"id":"c","trader":"u","desk":"A","city":"NYC","minute":"121","amount_usd":"500.00"},{"id":"d","trader":"v","desk":"B","city":"London","minute":"30","amount_usd":"400.00"},{"id":"e","trader":"v","desk":"B","city":"NYC","minute":"91","amount_usd":"100.00"}]}[{"id":"a","rules":["CITY_CONFLICT"]},{"id":"b","rules":["AMOUNT_LIMIT","CITY_CONFLICT"]},{"id":"c","rules":[]},{"id":"d","rules":[]},{"id":"e","rules":[]}]a and b differ in city and are exactly 60 minutes apart. Only b exceeds 1000.00. The gaps from b to c and from d to e are 61 minutes, so those pairs do not conflict.Part 2 — Configurable desk-window policiesevaluate_executions(records: list[dict[str, str]], desk_rules: list[dict[str, str]] | None = None) without replacing the Part 1 rules.name, window_minutes, and cap_usd.t, sum amounts for its desk across all traders in the inclusive interval [t - window_minutes, t]. Include all executions tied at t, irrespective of input order.cap_usd. This does not automatically flag other members of its window; each execution is evaluated at its own timestamp.desk_rules is provided, return an object containing records, with the Part 1 result shape, and breaches, with one {id, rule, total_usd} item per violated desk rule. Format totals with exactly two decimal places. Order breaches by input-record position, then rule name. An empty configuration list still selects this extended output shape.{"records":[{"id":"p","trader":"p1","desk":"A","city":"NYC","minute":"0","amount_usd":"900.00"},{"id":"q","trader":"q1","desk":"A","city":"NYC","minute":"30","amount_usd":"900.00"},{"id":"r","trader":"r1","desk":"A","city":"NYC","minute":"60","amount_usd":"800.00"},{"id":"s","trader":"s1","desk":"A","city":"NYC","minute":"61","amount_usd":"1000.00"}],"desk_rules":[{"name":"DESK_60M","window_minutes":"60","cap_usd":"2500.00"}]}{"records":[{"id":"p","rules":[]},{"id":"q","rules":[]},{"id":"r","rules":["DESK_60M"]},{"id":"s","rules":["DESK_60M"]}],"breaches":[{"id":"r","rule":"DESK_60M","total_usd":"2600.00"},{"id":"s","rule":"DESK_60M","total_usd":"2700.00"}]}900.00 and 1800.00. At minute 60, the inclusive window contains p + q + r = 900 + 900 + 800 = 2600, exceeding 2500. At minute 61, p expires, giving q + r + s = 900 + 800 + 1000 = 2700. No execution exceeds the individual amount limit, and every trader is distinct.Example 3:{"records":[{"id":"x","trader":"u","desk":"A","city":"London","minute":"60","amount_usd":"1500.00"},{"id":"y","trader":"u","desk":"A","city":"NYC","minute":"0","amount_usd":"1000.00"},{"id":"z","trader":"v","desk":"A","city":"NYC","minute":"60","amount_usd":"0.00"},{"id":"w","trader":"u","desk":"A","city":"NYC","minute":"120","amount_usd":"1000.00"},{"id":"v","trader":"k","desk":"B","city":"NYC","minute":"60","amount_usd":"999.00"}],"desk_rules":[{"name":"DESK_60M","window_minutes":"60","cap_usd":"2000.00"}]}{"records":[{"id":"x","rules":["AMOUNT_LIMIT","CITY_CONFLICT","DESK_60M"]},{"id":"y","rules":["CITY_CONFLICT"]},{"id":"z","rules":["DESK_60M"]},{"id":"w","rules":["CITY_CONFLICT","DESK_60M"]},{"id":"v","rules":[]}],"breaches":[{"id":"x","rule":"DESK_60M","total_usd":"2500.00"},{"id":"z","rule":"DESK_60M","total_usd":"2500.00"},{"id":"w","rule":"DESK_60M","total_usd":"2500.00"}]}x exceeds the individual limit and conflicts with both y and w, each exactly 60 minutes away. At minute 60, both x and z see y + x + z = 1000 + 1500 + 0 = 2500. At minute 120, w sees x + z + w = 1500 + 0 + 1000 = 2500; already-flagged x is not excluded. These totals exceed 2000. At minute 0, desk A totals 1000; desk B independently totals 999 at minute 60.Notes:O(n log n + kn + k log k) time for n executions and k desk rules.Sea API and an axis-aligned rectangle defined by integer-coordinate points bottom_left and top_right. Each ship occupies a distinct integer-coordinate point.The API method has_ships(top_right, bottom_left) returns true if at least one ship lies inside the specified rectangle, including its boundaries, and false otherwise. It does not reveal ship locations or counts. You may call it only with a valid rectangle.Implement count_ships to return the exact number of ships in the requested rectangle using at most 400 API calls. There are at most 10 ships in the entire coordinate domain. You cannot inspect the API's internal data, and ships outside the requested rectangle must not be counted.Function or class signatureSea.has_ships(top_right: tuple[int, int], bottom_left: tuple[int, int]) -> boolcount_ships(sea: Sea, top_right: tuple[int, int], bottom_left: tuple[int, int]) -> int(x, y).Example 1:[(1, 1), (2, 2), (3, 3), (8, 8)]; top_right = (4, 4); bottom_left = (1, 1).3(1, 1) is included because boundaries are inclusive; (8, 8) is outside. Locations are shown only to explain the example and are not supplied to your function.[(0, 0), (5, 0), (5, 5)]; top_right = (5, 0); bottom_left = (1, 0).1(5, 0), excludes (0, 0), and does not include (5, 5).[0, 1000].bottom_left.x <= top_right.x and bottom_left.y <= top_right.y.0 and 10 ships in the entire domain, with no duplicate locations.count_ships may make at most 400 API calls.0 to 10^9, and the maximum ship count is an input parameter K. Derive an API-call bound in terms of K and the rectangle's dimensions, and explain whether a fixed 400-call budget can still be guaranteed.def min_transaction_cost(prices: List[Tuple[int, int, int]], queries: List[Tuple[int, int]]) -> List[int]:prices = [(1, 2, 100), (1, 3, 200), (2, 3, 50)], queries = [(1, 3), (1, 2)] [150, 100] prices = [(1, 4, 300), (4, 5, 100), (1, 5, 600)], queries = [(1, 5), (1, 4)] [400, 300] 1 <= prices.length <= 10^4 1 <= queries.length <= 10^4 1 <= prices[i][0], prices[i][1] <= 10^6 0 <= prices[i][2] <= 10^4 class KthLargest:def __init__(self, k: int, nums: List[int]) -> None:def add(self, val: int) -> int:k = 3, nums = [4, 5, 8, 2] → Output after add(3): 4, Explanation: The current stream is [4, 5, 8, 2, 3], and the 3rd largest number is 4.Example 2: With Input: k = 1, nums = [] → Output after add(5): 5, Explanation: There is only one number 5, which is the 1st largest by default.Constraints:1 <= k <= 10^4-10^4 <= nums[i] <= 10^4-10^4 <= val <= 10^410^4 calls will be made to add.add will be called at least once.def shortest_path(graph: Dict[str, List[Tuple[str, int]]], start: str) -> Dict[str, int]:graph = { 'A': [('B', 1), ('C', 4)], 'B': [('C', 2)], 'C': []}, start = 'A' {'A': 0, 'B': 1, 'C': 3} A, the shortest path to B is 1 and to C is 3 via B.graph = { 'X': [('Y', 5)], 'Y': [('Z', 1)], 'Z': []}, start = 'X' {'X': 0, 'Y': 5, 'Z': 6} X, the shortest path to Y is 5 and to Z is 6.1 and 1000. 100.k transactions (i.e., buy and sell the stock). Your goal is to maximize your profit. You can assume that you cannot sell a stock before you buy it. You need to implement a function that calculates the maximum profit that can be achieved with at most k transactions.Function signature: def max_profit(k: int, prices: List[int]) -> int:
k = 2, prices = [2, 4, 1, 7, 5] 7 k = 1, prices = [3, 2, 6, 5, 0, 3] 4 1 <= k <= 100 0 <= prices.length <= 1000 0 <= prices[i] <= 1000 def maxDepth(root: Optional[TreeNode]) -> int: root = [3,9,20,null,null,15,7] 3 root = [1,null,2] 2 [0, 10^4]. -100 <= Node.val <= 100 10^4 nodes.stock and each edge represents a transaction cost between two stocks, implement a function that returns the shortest path from a start_stock to an end_stock. If no path exists, return -1.def find_shortest_path(graph: Dict[str, List[Tuple[str, int]]], start_stock: str, end_stock: str) -> int:graph = {'A': [('B', 1), ('C', 4)], 'B': [('C', 2), ('D', 5)], 'C': [('D', 1)], 'D': []}, start_stock = 'A', end_stock = 'D' 4 graph = {'A': [('B', 5)], 'B': [('C', 3)], 'C': [], 'D': []}, start_stock = 'A', end_stock = 'D' -1 1000 stocks. 10,000. 1000. start_stock and end_stock are guaranteed to be valid stock identifiers in the graph.Sign up for free to access walkthroughs, AI-generated questions, and more.
Get Started Free