Pergunta de entrevista da empresa SentinelOne

1) Implement a simple HashMap (no need to write code, just describe) 2) Add ability to persist the Map data in a file, while keeping the set(key, value) method at O(1). 3) How can I overcome corrupted data if writing to disk is interrupted. (allowing only 1 write operation per call set() )

Resposta da entrevista

Sigiloso

27 de set. de 2017

1) Use an array of linked lists. use a hashCode function on the key, and modulus (%) operator to get the "slot" for the linked list. 2) File hold a simple list of [key,value] pairs, and we add to the HashMap (in memory model) a "File offset" param in each element of the linked list. That way when calling set() we find the element of the linked list, and after updating it, we know were we need to seek in the file. 3) Add checksum to each element, and verify it on startup (after crash).

1