Coinbase software engineer interviews cover algorithms, data structures, system design, and coding problems drawn from real interview rounds.
Question You are designing an NFT generation engine. You are given a set of Traits, where each trait has a name and a list of possible...
Input: ListQuestion You are building a block construction module for a blockchain node. The goal is to select a subset of pending transactions to include in...
Input: Graph (nodes and edges)Question Design a crypto trading system that manages a stream of orders. The system should support various operations like placing, pausing,...
Input: Array of stringsQuestion For this problem, you will be designing a series of different iterator classes. This problem is split into multiple related parts that...
Input: Array of integersQuestion For this problem, you will be designing a food delivery system. This problem is split into three related parts, evolving from basic data...
Input: ListQuestion 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)KnowledgeBaseSystem that stores articles with CRUD operations. The system operates entirely...Input: Graph (nodes and edges)account_id, the secondary key is an asset, and the value is an opaque decimal string such as "50.00".Each mutation has an integer timestamp. Mutation timestamps are strictly increasing across the entire store, including deletions of nonexistent keys. Reads may request any timestamp, including timestamps earlier than the most recent mutation. A read without a timestamp returns the latest state.A write makes its value visible starting at its timestamp, replacing the previous value for that account/asset pair. Deleting an asset makes that pair absent starting at the deletion timestamp. Deleting an account makes every asset belonging to that account absent, without destroying earlier history. Later writes may recreate an asset or account, but must not resurrect other previously deleted values.Historical reads return the state after all mutations whose timestamps are less than or equal to the requested timestamp. Reading a missing pair returns null; reading all assets of a missing account returns {}. Deleting a missing key is permitted and still consumes its timestamp. Reads do not change the store.An account deletion must not scan its assets. Each mutation should take amortized O(1) time, and a pair lookup should use binary search over the relevant histories rather than scan events. An account-wide read may inspect every distinct asset ever written under that account. Return maps have no required key order.Function or class signatureHistoricalBalanceStore() — construct an empty store.set(account_id: str, asset: str, value: str, timestamp: int) -> Nonedelete_asset(account_id: str, asset: str, timestamp: int) -> Nonedelete_account(account_id: str, timestamp: int) -> Noneget(account_id: str, asset: str, timestamp: int | None = None) -> str | Noneget_all(account_id: str, timestamp: int | None = None) -> dict[str, str]{
"operations": [
["set", "acct-A", "BTC", "0.50", 10],
["set", "acct-A", "ETH", "2.00", 20],
["set", "acct-A", "BTC", "0.75", 30],
["get", "acct-A", "BTC", 25],
["delete_asset", "acct-A", "BTC", 40],
["get", "acct-A", "BTC"],
["get_all", "acct-A", 35],
["get_all", "acct-A"]
]
}null:[null, null, null, "0.50", null, null, {"BTC": "0.75", "ETH": "2.00"}, {"ETH": "2.00"}]{
"operations": [
["set", "acct-B", "BTC", "1.00", 5],
["set", "acct-B", "ETH", "4.00", 8],
["delete_account", "acct-B", 12],
["get_all", "acct-B", 12],
["set", "acct-B", "BTC", "0.25", 15],
["get_all", "acct-B"],
["get_all", "acct-B", 11],
["delete_account", "acct-B", 18],
["get", "acct-B", "BTC", 15],
["get_all", "acct-B"]
]
}[null, null, null, {}, null, {"BTC": "0.25"}, {"BTC": "1.00", "ETH": "4.00"}, null, "0.25", {}]"0.25".Constraints:[1, 10^18]; mutation timestamps are globally strictly increasing. Query timestamps need not be increasing.get_all calls is at most 200,000, but accounts may have many historical assets that are currently absent.startNode to a destination wallet endNode. Each edge is equivalent to a transaction that can either be successful or failed. If no such path exists, return None.Function/class signature: def shortest_path(graph: Dict[str, List[str]], startNode: str, endNode: str) -> Optional[List[str]]:graph = { 'A': ['B', 'C'], 'B': ['D'], 'C': ['D'], 'D': [] } startNode = 'A' endNode = 'D' ['A', 'B', 'D'] graph = { 'A': ['B', 'C'], 'B': [], 'C': ['D'], 'D': [] } startNode = 'A' endNode = 'D' None TransactionFilter class that filters a list of transactions based on specific criteria. Each transaction is represented as a dictionary containing amount, currency, timestamp, and status. The class should have a method filter_transactions(transactions: List[Dict[str, Union[str, float]]], min_amount: float, currency_filter: str) -> List[Dict[str, Union[str, float]]] that returns all transactions where the amount is greater than or equal to min_amount and matches the given currency_filter. Function/class signature:class TransactionFilter: def filter_transactions(transactions: List[Dict[str, Union[str, float]]], min_amount: float, currency_filter: str) -> List[Dict[str, Union[str, float]]]: transactions = [{'amount': 100.0, 'currency': 'USD', 'timestamp': '2023-10-01', 'status': 'completed'}, {'amount': 50.5, 'currency': 'EUR', 'timestamp': '2023-10-02', 'status': 'pending'}, {'amount': 150.0, 'currency': 'USD', 'timestamp': '2023-10-03', 'status': 'completed'}], min_amount = 100.0, currency_filter = 'USD' [{'amount': 100.0, 'currency': 'USD', 'timestamp': '2023-10-01', 'status': 'completed'}, {'amount': 150.0, 'currency': 'USD', 'timestamp': '2023-10-03', 'status': 'completed'}] min_amount of 100.0 and are in USD. transactions = [{'amount': 200.0, 'currency': 'USD', 'timestamp': '2023-09-01', 'status': 'completed'}, {'amount': 60.0, 'currency': 'EUR', 'timestamp': '2023-09-02', 'status': 'failed'}, {'amount': 150.0, 'currency': 'EUR', 'timestamp': '2023-09-03', 'status': 'completed'}], min_amount = 70.0, currency_filter = 'EUR' [{'amount': 150.0, 'currency': 'EUR', 'timestamp': '2023-09-03', 'status': 'completed'}] EUR. def max_profit(prices: List[int]) -> int:[7, 1, 5, 3, 6, 4]5[7, 6, 4, 3, 1]01 <= prices.length <= 10^5 0 <= prices[i] <= 10^4n + 1 integers where each integer is in the range [1, n], write a function to find the duplicate number. You must solve it without modifying the array and using O(1) extra space. Your solution should have a time complexity better than O(n^2).def find_duplicate(nums: List[int]) -> int:[3, 1, 3, 4, 2]33 appears twice.[1, 2, 3, 4, 4]44 appears twice.2 <= n <= 10^5[1, n] and there is at least one duplicate.src to a destination transaction dest. The graph is given as an adjacency list, and each edge has a non-negative cost.Function/class signature:def shortest_path(graph: Dict[str, List[Tuple[str, int]]], src: str, dest: str) -> Tuple[List[str], int]:graph = {"A": [("B", 1), ("C", 4)], "B": [("C", 2), ("D", 5)], "C": [("D", 1)], "D": []} src = "A", dest = "D" graph = {"X": [("Y", 2)], "Y": [("Z", 3)], "Z": []} src = "X", dest = "Z" 1 <= len(graph) <= 1000 0 <= cost <= 1000 n + 1 integers where each integer is in the range [1, n], find the duplicate number. You must solve it without modifying the array and using O(1) extra space. The solution should be optimized to have a better time complexity than O(n^2).def find_duplicate(nums: List[int]) -> int:[3, 1, 3, 4, 2] 3 3 is repeated in the array.[1, 3, 4, 2, 2] 2 2 is repeated in the array.1 <= n <= 10^5 [1, n] and there's guaranteed to be one duplicate.flights with columns flight_id, departure_airport, arrival_airport, and departure_time, you are required to return the flight_ids that have more than one layover. A layover is defined as having multiple connections in the journey from the departure to the final arrival airport. You should calculate the number of layovers by comparing the departure and arrival times of consecutive flights. def find_flights_with_layovers(flights: List[Tuple[int, str, str, str]]) -> List[int]:flights = [(1, 'A', 'B', '2023-01-02 08:00'), (2, 'B', 'C', '2023-01-02 10:00'), (3, 'C', 'D', '2023-01-02 12:00'), (4, 'A', 'D', '2023-01-02 09:00')]
Output: [1]
Explanation: Flight 1 has two layovers via B and C to reach D.
Example 2:
Input: flights = [(5, 'X', 'Y', '2023-01-03 07:00'), (6, 'Y', 'Z', '2023-01-03 09:00'), (7, 'Y', 'X', '2023-01-03 10:30')] [] departure_airport and arrival_airport are strings representing airport codes.d days window, compute the total number of distinct markets open during that window.def count_active_markets(timestamps: List[Tuple[int, int]], d: int) -> int: returns an integer count of active markets.timestamps = [(1, 5), (2, 3), (4, 6)], d = 3 2 timestamps = [(1, 2), (3, 5), (7, 10)], d = 3 1 1 to 4.Constraints: 1 <= timestamps.length <= 1000 1 <= d <= 10000 source user to the destination user. Users can have multiple transactions but there is a constraint on transaction types that can be traversed.def shortest_path(transactions: List[Tuple[int, int]], source: int, destination: int) -> List[int]: returns a list of users representing the shortest path.transactions = [(1, 2), (2, 3), (2, 4), (3, 4)] [1, 2, 3] transactions = [(1, 2), (1, 3), (3, 4), (2, 4)] [1, 3, 4] 1 <= transactions.length <= 100 1 <= source, destination <= 10^4 set creates a new version without destroying older versions. An empty string is a valid value and is different from a missing value.ValueError, without changing any state.None for a missing setting. Reads before the first mutation or after the last mutation are valid.delete_subkey makes one setting absent from its timestamp onward. delete_key makes every setting under that product absent from its timestamp onward. Both preserve historical reads. A subsequent set recreates only the specified setting: it must not resurrect other deleted settings.get_all returns a new dictionary containing only settings visible at the requested time. Return an empty dictionary for a product with no visible settings. Dictionary order is not significant, and modifying a returned dictionary must not change the store.delete_key. Historical point reads must use binary search rather than scanning every version. Deletes of missing products or settings are valid mutations.Class APIAssetConfigStore() — construct an empty store.set(product: str, setting: str, value: str, timestamp: int) -> None — append a setting version.get(product: str, setting: str, timestamp: Optional[int] = None) -> Optional[str] — retrieve the visible value at the requested time.get_all(product: str, timestamp: Optional[int] = None) -> dict[str, str] — retrieve all visible settings for a product.delete_subkey(product: str, setting: str, timestamp: int) -> None — append a setting-deletion marker.delete_key(product: str, timestamp: int) -> None — append a product-deletion marker without visiting its settings.set("BTC-USD", "min_order", "0.0001", 10)
set("BTC-USD", "status", "online", 20)
set("BTC-USD", "min_order", "0.0002", 30)
get("BTC-USD", "min_order", 25)
delete_key("BTC-USD", 40)
get_all("BTC-USD", 35)
get_all("BTC-USD", 40)
set("BTC-USD", "status", "post_only", 50)
get_all("BTC-USD")null represents None):[null, null, null, "0.0001", null, {"min_order": "0.0002", "status": "online"}, {}, null, {"status": "post_only"}]status, but the older min_order remains deleted.Example 2:set("ETH-USD", "notice", "", 5)
get("ETH-USD", "notice", 4)
get("ETH-USD", "notice", 5)
delete_subkey("ETH-USD", "notice", 8)
get("ETH-USD", "notice", 8)
set("ETH-USD", "notice", "maintenance", 12)
get_all("ETH-USD", 7)
get_all("ETH-USD", 10)
get_all("ETH-USD", 100)[null, null, "", null, null, null, {"notice": ""}, {}, {"notice": "maintenance"}]maintenance at 12. A future read sees all mutations recorded so far.Constraints[0, 10^12]. Out-of-range read timestamps also raise ValueError. String arguments and argument types satisfy the stated bounds.get_all may inspect every setting ever recorded for the product.follow(follower_id: int, followee_id: int), unfollow(follower_id: int, followee_id: int), and get_feed(user_id: int) -> List[int]. The feed should return the most recent 10 transactions from the followed users.def follow(follower_id: int, followee_id: int) -> None: update the following relationship.def unfollow(follower_id: int, followee_id: int) -> None: remove the following relationship.def get_feed(user_id: int) -> List[int]: return the user feed containing transaction IDs of the most recent 10 transactions from followed users.manager = FeedManager() manager.follow(1, 2) manager.follow(1, 3) manager.get_feed(1) [x, y, z] 1 <= follower_id, followee_id <= 10^4 10^5.get(key: int) -> int and put(key: int, value: int) -> void methods.def get(key: int) -> int: returns the value of the key if it exists or -1.def put(key: int, value: int) -> None: updates the value if the key exists, otherwise, adds the key-value pair to the cache. If the cache reaches its capacity, it should invalidate the least recently used item before inserting a new item.cache = LRUCache(2) cache.put(1, 1) cache.put(2, 2) cache.get(1) 1 cache.put(3, 3) cache.get(2) -1 1 <= capacity <= 3000 0 <= key, value <= 10^4.Sign up for free to access walkthroughs, AI-generated questions, and more.
Get Started Free