Stack Bash - Master data structures and algorithms

Optimize a Crypto Exchange

Medium
Imagine you're the lead dev working on a cryptocurrency exchange.
Let's say the market is hot, and millions of users are looking up the current prices of various cryptocurrencies.
However there are millions of cryptocurrencies, and retrieving the prices of each could be time consuming.
The good news is that in this bull run, people are mostly looking up a handful of cryptocurrencies.
Let's say that you're allowed to set up caching, but only at a limited capacity.
Implement an LRUCache class (Least Recently Used) that can update and store a handful of cryptocurrency tickers and their current price.
The class should contain the following methods:
  • add(ticker, price) both adds or updates a ticker and its price (for example BTC). When this happens, this ticker becomes Most recently used.
  • lookup(ticker) returns the cryptocurrency's price, and marks that ticker as most recently used
As items are added to your LRUCache, be sure to evict the least recently used tickers out of your cache to keep it within the provided capacity.

Try it first

Solution

6 Essential Hash Tables Coding Interview Problems

Master Hash Tables by trying the coding challenges below.
  1. 1.Two sumEasy
  2. 2.Palindrome CheckEasy
  3. 3.Cover SetMedium
  4. 4.Missing numberMedium
  5. 5.Crypto ExchangeMedium
  6. 6.Distinct SubarrayHard

Want to confidently pass your next coding interview?

Stack Bash helps new and veteran software engineers master data structures and algorithms for technical interviews.