Amazon interview question

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

Interview Answers

Anonymous

7 Sept 2011

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

Anonymous

23 Sept 2011

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

Anonymous

17 Feb 2012

Hash table

Anonymous

19 Oct 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.