Basic Components Implementation Flashcards

1
Q

How to implement LRU / MRU cache?

A

Hash Table + Link list

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

How to implement LFU cache?

A

Hash Table + Sorted List
(similar to Redis sorted set)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

How to keep records from the last x secs or minutes?
What is the use case for this?

A

Redis Sorted set where the score is the timestamp.
ZREM RANGE BY SCORE
Use case: API Rate Limiting

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

How to keep the rank of all players in a tournament?

A

Redis Sorted set where the score is the points (logN)
ZREM RANGE BY RANK
Use case: Lichess

How well did you know this?
1
Not at all
2
3
4
5
Perfectly