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
). lmplement the data structures and algorithms to support these operations. That is, implement the method track (int x)
, which is called when each number is generated, and the method getRankOfNumber(int x)
, which returns the number of values less than or equal to x
.
Note: This problem is slightly different from the original one in the book.
Example:
Input: ["StreamRank", "getRankOfNumber", "track", "getRankOfNumber"] [[], [1], [0], [0]] Output: [null,0,null,1]
Note:
x <= 50000
track
and getRankOfNumber
methods are less than or equal to 2000.