Amazon || SDE2 Onsite || Rank of an element in a stream
Anonymous User
1942

Imagine you are reading in a stream of integers. Periodically, you wish to be able to look up the rank of a number x (the number of values less than or equal to x). Implement the data structures and algorithms to support these operations. That is, implement the method track(int x), which is called when each number of values less than or equal to x (not including x itself).
Following up:

  1. Analyze the tradeoff between add() and getRank()?
  2. how can we make the time complexity of getRank() to become O(1)?
Comments (4)