Coinbase logo

Coinbase Interview Questions

54 practice questions for Coinbase technical interviews

Coinbase software engineer interviews cover algorithms, data structures, system design, and coding problems drawn from real interview rounds.

Software Engineer Backend Engineer Frontend Engineer Full Stack Engineer Mobile Engineer Data Engineer Data Scientist ML Engineer DevOps Engineer DevOps Engineer Product Manager SRE Security Engineer Engineering Manager Data Analyst UX/UI Designer QA Engineer
coding Medium Verified Question #1

1. Generate NFT


Category: String coding problem

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: List
Output: Array
Want to practise this one?
Create a free account to open the full question and practise Coinbase questions with AI.
Sign up free
coding Medium Verified Question #2

2. Blockchain Mining


Category: Dynamic programming coding problem

Question 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)
Output: Computed result
coding Medium Verified Question #3

3. Crypto Trading System Stream


Category: String coding problem

Question Design a crypto trading system that manages a stream of orders. The system should support various operations like placing, pausing,...

Input: Array of strings
Output: Computed result
coding Hard Verified Question #4

4. Design Iterators


Category: Array coding problem

Question 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 integers
Output: Computed result
coding Medium Verified Question #5

5. Food Delivery System


Category: Trie-based coding problem

Question For this problem, you will be designing a food delivery system. This problem is split into three related parts, evolving from basic data...

Input: List
Output: Computed result
coding Hard Verified Question #6

6. Transaction System


Category: Tree coding problem
For this problem, you will be designing a system to handle financial transactions and account balances. This problem is split into three related...
Input: List
Output: Integer
coding Hard Verified Question #7

7. OA[CodeSignal] Cloud File Storage System


Category: Graph coding problem

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)
Output: Array
coding Hard Verified Question #8

8. OA[CodeSignal] Design Banking System


Category: Graph coding problem

Question Design a banking system that supports account management, transactions, and various financial operations.

Input: Graph (nodes and edges)
Output: Computed result
coding Hard Verified Question #9

9. Capital Gains Tax Calculator


Category: String coding problem
You are given a chronologically sorted list of stock transactions. Each transaction is a list of strings in the format `[<timestamp>, <type>,...
Input: Array of strings
Output: Computed result
coding Medium Verified Question #10

10. Service Log Aggregator


Category: Trie-based coding problem
A distributed system emits log entries from multiple services and worker threads. Each log entry is a colon-separated string in the format...
Input: Array
Output: Computed result
coding Hard Verified Question #11

11. OA [CodeSignal] Knowledge Base System


Category: Graph coding problem
Design and implement a personal knowledge base called KnowledgeBaseSystem that stores articles with CRUD operations. The system operates entirely...
Input: Graph (nodes and edges)
Output: Computed result
coding Medium Verified Question #12

12. OA [CodeSignal] Workspace Tracker


Category: Interval-based coding problem
Build a system to track desk workers at a shared office space. The system records when each worker enters and leaves and computes how long they have...
Input: String
Output: Array
coding Hard Verified Question #13

13. Transaction Query Engine


Category: String coding problem
Design a system to filter and paginate a list of transaction records. Each record is a list of strings in the format `[timestamp, id, userId,...
Input: Array of strings
Output: Computed result
coding Medium Verified Question #14

14. Exchange Rate Finder


Category: String coding problem
You are given a set of currency exchange relationships. Each relationship specifies a direct exchange rate between two currencies. Rates are...
Input: List
Output: Computed result
coding Hard Verified Question #15

15. Order Matching Engine


Category: String coding problem
You are managing a cryptocurrency order book. The book holds buy and sell orders placed by traders. - A buy order indicates the maximum price a...
Input: String
Output: Computed result
coding Hard Verified Question #16

16. Account Transfer System


Category: String coding problem
You are given a list of fund transfer instructions and a set of accounts with initial balances. Each transfer moves a fixed percentage of the...
Input: List
Output: Computed result
coding Hard Verified Question #17

17. Restaurant Delivery Network


Category: String coding problem
You are building a food discovery platform. Given a user's location, a list of restaurants with their coordinates, and a menu of items with prices,...
Input: List
Output: Computed result
coding Hard hash map #1

1. [Hash Map + Binary Search] — Two-key historical store with hierarchical deletion


Background
Coinbase wallet and account interfaces display balances for multiple assets, while support investigations may need an earlier view of the same account. Model an in-memory store of derived balance snapshots keyed by account and asset; this is a queryable projection, not an authoritative financial ledger.
Problem statement
Implement HistoricalBalanceStore, a two-key, timestamped key-value store. The primary key is an 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 signature
  • HistoricalBalanceStore() — construct an empty store.

  • set(account_id: str, asset: str, value: str, timestamp: int) -> None

  • delete_asset(account_id: str, asset: str, timestamp: int) -> None

  • delete_account(account_id: str, timestamp: int) -> None

  • get(account_id: str, asset: str, timestamp: int | None = None) -> str | None

  • get_all(account_id: str, timestamp: int | None = None) -> dict[str, str]


Example 1:
Input, with each operation applied to one initially empty store:
{
  "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"]
  ]
}

Output, one result per operation; mutations return null:
[null, null, null, "0.50", null, null, {"BTC": "0.75", "ETH": "2.00"}, {"ETH": "2.00"}]

Explanation: At timestamp 25, BTC still has its timestamp-10 value. The deletion at timestamp 40 hides BTC from the latest view, but not from the timestamp-35 view.
Example 2:
Input:
{
  "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"]
  ]
}

Output:
[null, null, null, {}, null, {"BTC": "0.25"}, {"BTC": "1.00", "ETH": "4.00"}, null, "0.25", {}]

Explanation: The deletion at 12 hides both assets. Writing BTC at 15 recreates only BTC, not ETH. The second account deletion hides the recreated BTC from the latest view, while the historical read at 15 still returns "0.25".
Constraints:
  • At most 200,000 method calls, excluding construction.

  • Account IDs and asset names are nonempty strings of at most 64 characters.

  • Values are valid nonnegative decimal strings of at most 40 characters; no arithmetic or normalization is required.

  • Timestamps are integers in [1, 10^18]; mutation timestamps are globally strictly increasing. Query timestamps need not be increasing.

  • The total number of entries returned by all get_all calls is at most 200,000, but accounts may have many historical assets that are currently absent.

  • Execution is single-threaded; all history must remain queryable.


Follow-up:
How would you change the data structures if mutations could arrive out of timestamp order, while preserving historical account-deletion semantics and avoiding an asset scan on account deletion? Assume mutation timestamps remain globally unique.
Want to practise this one?
Create a free account to open the full question and practise Coinbase questions with AI.
Sign up free
coding Medium graph #2

2. Graph — Find the shortest path in a cryptocurrency transaction network


Background: In the world of cryptocurrency, understanding the quickest way to transfer assets across different wallets is critical for maintaining low transaction fees and efficient trading. This problem relates to optimizing transfers in Coinbase's wallet services.
Problem statement: Given a directed graph where nodes represent wallets and edges represent direct transactions between them, you need to find the shortest path (in terms of transaction hops) from a starting wallet 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]]:


Example 1:
Input:
graph = { 'A': ['B', 'C'], 'B': ['D'], 'C': ['D'], 'D': [] }
startNode = 'A'
endNode = 'D'
Output:
['A', 'B', 'D']
Explanation: The shortest path from A to D is through B.
Example 2:
Input:
graph = { 'A': ['B', 'C'], 'B': [], 'C': ['D'], 'D': [] }
startNode = 'A'
endNode = 'D'
Output:
None
Explanation: There is no path from A to D.
Constraints:
  • Node names are alphanumeric strings with max length 50.

  • Graph can have up to 10^5 nodes.

  • Transactions (edges) can be up to 2 * 10^5 in the worst case.
coding Medium filtering #3

3. Coding — Implement a transaction filtering system


Background: As a cryptocurrency exchange, Coinbase needs to efficiently manage and filter transaction data to ensure compliance and enhance user security. This system should enable the detection of suspicious transactions and provide insights for further investigation.
Problem statement: You are tasked with building a 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]]]:


Example 1:
  • Input: 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'

  • Output: [{'amount': 100.0, 'currency': 'USD', 'timestamp': '2023-10-01', 'status': 'completed'}, {'amount': 150.0, 'currency': 'USD', 'timestamp': '2023-10-03', 'status': 'completed'}]

  • Explanation: Both transactions exceed the min_amount of 100.0 and are in USD.


Example 2:
  • Input: 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'

  • Output: [{'amount': 150.0, 'currency': 'EUR', 'timestamp': '2023-09-03', 'status': 'completed'}]

  • Explanation: Only the last transaction meets the criteria of being greater than or equal to 70.0 and in EUR.


Constraints:
  • All amounts are positive floats,

  • Currency strings are limited to three uppercase letters,

  • List of transactions has at most 10^4 entries.
coding Medium dynamic programming #4

4. [Dynamic Programming] — Maximum Profit from Cryptocurrency Trading

Background: Coinbase seeks to optimize user trading strategies to enhance profit margins during market fluctuations. A well-structured algorithm can help calculate the best times to buy and sell currencies based on historical data.
Problem statement: Given an array of integers representing the prices of a cryptocurrency over a series of days, implement a function to determine the maximum profit that could be made by buying on one day and selling on another. You may only complete one transaction (i.e., buy one and sell one share of the cryptocurrency). The function should return 0 if no profit can be made.
Function Signature: def max_profit(prices: List[int]) -> int:
Example 1:
  • Input: [7, 1, 5, 3, 6, 4]

  • Output: 5

  • Explanation: Buy on day 2 (price = 1) and sell on day 5 (price = 6), profit = 6 - 1 = 5.


Example 2:
  • Input: [7, 6, 4, 3, 1]

  • Output: 0

  • Explanation: In this case, no transactions are done and the max profit = 0.


Constraints:
  • 1 <= prices.length <= 10^5

  • 0 <= prices[i] <= 10^4
coding Medium array #5

5. Find Duplicate Number — Efficient search for duplicates in an array

Background: In the context of cryptocurrency transactions, identifying duplicate transactions is crucial for maintaining the integrity of financial records. This problem relates to ensuring that no transaction is processed more than once on the Coinbase platform.
Problem statement: Given an array of n + 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).
Function/class signature:
  • def find_duplicate(nums: List[int]) -> int:

Example 1:
Input: [3, 1, 3, 4, 2]
Output: 3
Explanation: The number 3 appears twice.
Example 2:
Input: [1, 2, 3, 4, 4]
Output: 4
Explanation: The number 4 appears twice.
Constraints:
  • 2 <= n <= 10^5

  • The integers in the array are in the range [1, n] and there is at least one duplicate.
coding Medium graph #6

6. Graph — Find the shortest path in a cryptocurrency transaction network


Background: Coinbase deals with numerous cryptocurrency transactions that form a network. Calculating the shortest path between two transactions can help optimize network routes for better performance and reduced costs.
Problem statement: Given a directed graph where each node represents a cryptocurrency transaction and each directed edge represents a possible transaction path with an associated cost, implement a function to find the shortest path from a starting transaction 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]:


Example 1:
Input:
graph = {"A": [("B", 1), ("C", 4)], "B": [("C", 2), ("D", 5)], "C": [("D", 1)], "D": []}
src = "A", dest = "D"
Output: (['A', 'B', 'C', 'D'], 4)
Explanation: The shortest path is A -> B -> C -> D with a total cost of 4.
Example 2:
Input:
graph = {"X": [("Y", 2)], "Y": [("Z", 3)], "Z": []}
src = "X", dest = "Z"
Output: (['X', 'Y', 'Z'], 5)
Explanation: The shortest path is X -> Y -> Z with a total cost of 5.
Constraints:
  • 1 <= len(graph) <= 1000

  • 0 <= cost <= 1000

  • All transaction identifiers are unique strings.
coding Medium two pointers #7

7. [Two Pointers] — Find Duplicate Number in an Array

Background: In a financial app like Coinbase, ensuring the integrity of user data is critical. Identifying duplicates efficiently within a user's transaction history can help prevent fraud and maintain accurate records.
Problem statement: Given an array of 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).
Function/class signature:
  • def find_duplicate(nums: List[int]) -> int:

Example 1:
  • Input: [3, 1, 3, 4, 2]

  • Output: 3

  • Explanation: The number 3 is repeated in the array.

Example 2:
  • Input: [1, 3, 4, 2, 2]

  • Output: 2

  • Explanation: The number 2 is repeated in the array.

Constraints:
  • 1 <= n <= 10^5

  • The integer values are in the range [1, n] and there's guaranteed to be one duplicate.
coding Medium database #8

8. SQL Window Functions — Identify Flights with Layovers

Background: Coinbase needs to efficiently analyze flight data for potential integration with a cryptocurrency travel service. Understanding flight layovers can help users plan better travel routes using digital currencies.
Problem statement: Given a table 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.
Function/class signature:
  • def find_flights_with_layovers(flights: List[Tuple[int, str, str, str]]) -> List[int]:

Example 1:
Input: 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')]
Output: []
Constraints:
  • 1 <= len(flights) <= 10^4

  • Each flight_id is unique.

  • Time format is guaranteed to be ‘YYYY-MM-DD HH:MM’.

  • departure_airport and arrival_airport are strings representing airport codes.

coding Senior sliding window #9

9. [OA] Sliding Window — track active crypto markets over time

In the ever-changing world of cryptocurrency, it's crucial for Coinbase to determine the number of distinct markets that remain active within any given time frame.
Problem statement: Given an array of timestamps when markets were opened and closed, and a d days window, compute the total number of distinct markets open during that window.
  • Function signature: def count_active_markets(timestamps: List[Tuple[int, int]], d: int) -> int: returns an integer count of active markets.


Example 1:
Input: timestamps = [(1, 5), (2, 3), (4, 6)], d = 3
Output: 2
Explanation: Markets 1 and 2 overlap in the window [1, 4].
Example 2:
Input: timestamps = [(1, 2), (3, 5), (7, 10)], d = 3
Output: 1
Explanation: Only one market is active at any time in the window 1 to 4.
Constraints:
  • 1 <= timestamps.length <= 1000

  • 1 <= d <= 10000

  • Timestamps are unique.
coding Senior graph #10

10. [OA] Graph Traversal — Find the shortest path for crypto transactions

In Coinbase's ecosystem, efficient transaction routing is crucial for timely processing. The goal is to determine the shortest path between users in a peer-to-peer transaction graph.
Problem statement: Given a directed graph representing users and their transactions as edges, write a function to find the shortest path from the source user to the destination user. Users can have multiple transactions but there is a constraint on transaction types that can be traversed.
  • Function signature: def shortest_path(transactions: List[Tuple[int, int]], source: int, destination: int) -> List[int]: returns a list of users representing the shortest path.


Example 1:
Input: transactions = [(1, 2), (2, 3), (2, 4), (3, 4)]
Output: [1, 2, 3]
Explanation: The path from user 1 to user 3 is through user 2.
Example 2:
Input: transactions = [(1, 2), (1, 3), (3, 4), (2, 4)]
Output: [1, 3, 4]
Explanation: The path from user 1 to user 4 is through user 3.
Constraints:
  • 1 <= transactions.length <= 100

  • 1 <= source, destination <= 10^4

  • All transactions are unique.
system design Hard database #11

11. Design AssetConfigStore — versioned trading configuration with historical reads


Background
Coinbase Exchange supports many trading products, such as BTC-USD, whose operational configuration can change over time. Model an in-memory configuration component that lets trading-support tools retrieve current settings and lets incident investigators reconstruct settings at a historical timestamp. This is a practice adaptation of the reported Coinbase timestamped, two-level key-value-store exercise, not a description of Coinbase's internal implementation.
Requirements
1. Store string values under a product key and setting subkey. set creates a new version without destroying older versions. An empty string is a valid value and is different from a missing value.
2. Every mutation has an integer timestamp. Mutation timestamps must be strictly increasing across the entire store, including deletes of nonexistent entries. Reject an out-of-range or non-increasing mutation timestamp with ValueError, without changing any state.
3. Reads accept an optional timestamp. An omitted timestamp means the latest state; a supplied timestamp means the state after all mutations at or before that timestamp. Return None for a missing setting. Reads before the first mutation or after the last mutation are valid.
4. 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.
5. 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.
6. Use lazy product-deletion markers rather than scanning every setting during delete_key. Historical point reads must use binary search rather than scanning every version. Deletes of missing products or settings are valid mutations.
Class API
  • AssetConfigStore() — 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.


Example 1:
Input sequence of method calls on a new store:
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")

Output, one entry per call (null represents None):
[null, null, null, "0.0001", null, {"min_order": "0.0002", "status": "online"}, {}, null, {"status": "post_only"}]

Explanation: The update at 30 is not visible at 25. Deleting the product at 40 leaves its state at 35 intact. The write at 50 recreates status, but the older min_order remains deleted.
Example 2:
Input sequence of method calls on a new store:
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)

Output:
[null, null, "", null, null, null, {"notice": ""}, {}, {"notice": "maintenance"}]

Explanation: The empty string is a present value at timestamps 5 through 7. The setting is absent from 8 through 11, then becomes maintenance at 12. A future read sees all mutations recorded so far.
Constraints
  • At most 200,000 API calls; product and setting names are nonempty strings of at most 100 characters, and values have at most 1,000 characters.

  • Supplied timestamps are integers in [0, 10^12]. Out-of-range read timestamps also raise ValueError. String arguments and argument types satisfy the stated bounds.

  • Calls execute sequentially in one process. Persistence, expiration, history compaction, and concurrency are out of scope.

  • Target amortized O(1) writes and deletions, excluding string hashing; product deletion must be independent of the number of settings. get_all may inspect every setting ever recorded for the product.
system design Senior api design #12

12. [OA] Twitter Feed — Design a user feed for Coinbase's social trading features

As Coinbase looks to integrate social features for trading, it's essential to design a system that tracks user feeds efficiently.
Problem statement: Design a class to manage a user's feed. Supports the following methods: 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.
  • Method signatures:

- 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.
Example 1:
Input: manager = FeedManager()
manager.follow(1, 2)
manager.follow(1, 3)
manager.get_feed(1)
Output: [x, y, z]
Constraints:
  • 1 <= follower_id, followee_id <= 10^4

  • Transaction history size can be up to 10^5.
system design Senior caching #13

13. [OA] LRU Cache — Design a caching layer for Coinbase's API responses

In order to optimize data retrieval times and minimize database load, Coinbase requires an LRU cache to manage frequent API requests efficiently.
Problem statement: Design and implement a class that represents an LRU Cache with a fixed capacity. Supports get(key: int) -> int and put(key: int, value: int) -> void methods.
  • Method signatures:

- 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.
Example 1:
Input: cache = LRUCache(2)
cache.put(1, 1)
cache.put(2, 2)
cache.get(1)
Output: 1
cache.put(3, 3)
cache.get(2)
Output: -1
Constraints:
  • 1 <= capacity <= 3000

  • 0 <= key, value <= 10^4.

Start practicing Coinbase questions

Sign up for free to access walkthroughs, AI-generated questions, and more.

Get Started Free