Uber phone screen - String cache

4901
Jan 24, 2018
Jun 23, 2019

FIFO Cache of N Strings. Both methods should run in constant time.

class Cache {
    final int N;
    void add (String element) {
    // Implement constant-time here.
    {
    boolean contains (String element) {
    // Implement constant-time here.
    }
}

Curve-ball to complicate the implementation. Implement remove in constant time.

void remove (String element) {
// Implement constant-time here.
}
  1. Do not ignore duplicate entries.
  2. If cache size N is reached, FIFO implementation should pop the first element from the cache for every new entry.
Comments (10)