Uber phone screen - String cache
Difficulty: MEDIUMCategory: InterviewExperienceFrequency: 1Asked On 2018-01-24Added By Anonymous
Source: Link
Company: Uber
Role: unknown
Interview Stage: Phone Screen
Location: unknown
Year: unknown
Original Post Content:
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.