Pergunta de entrevista da empresa Amazon

How would you implement a sparse array (key could be any integer, but only a few would be used) with limited memory.

Respostas da entrevista

Sigiloso

7 de set. de 2011

A hash table. A linked list is possible but random access isn't efficient

Sigiloso

23 de set. de 2011

need to support efficient sequential read as well. b-tree

Sigiloso

17 de fev. de 2012

Hash table

Sigiloso

19 de out. de 2011

Assuming sparse means many values are zero: have 2 arrays: one to store non-zero indexes, the other to store the values at the non-zero index. If queried number is not in the index set, return 0.