Senior Engineer | Online test | Live Ramp
Anonymous User
2009

Implement a data structure which allows key-value elements to be added and retrieved. The data structure should fulfill the following requirements:

  • It is possible to add and retrieve an element;
  • Adding an element replaces a value whose key already exists in the structure;
  • Elements are added with a Time-To-Leave expressed in millliseconds;
  • Once the Time-To-Leave of an element is reached, it is considered to be non-existent;
  • The structure has a limited capacity defined in the constructor call;
  • An element whose Time-To-Leave is lower then the lowest Time-To-Leave in the structure should not be added.
  • When adding an element to a full structure, the pair with the lowest Time-To-Leave shall be replaced if there's no other entry with the same key already stored;
  • The data structure provides information about its current size.
Comments (2)