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.
}- Do not ignore duplicate entries.
- If cache size N is reached, FIFO implementation should pop the first element from the cache for every new entry.
Comments (10)


