Flipkart SDE1 Interview Question
Anonymous User
1330

Given the data of the form (timestamp, value), find the maximum value for the last X milliseconds.

Assumptions:

  1. Timestamp is in monotonically increasing order and in milliseconds (we can generate current time on own).
  2. We can decide the value of X.

Develop below 2 functions
record(value): function stores the value with current time-stamp
max_value(): function finds the maximum value in the last X milliseconds.

Example (Assume X=100)
record(1) -> timestamp - 101
record(4) -> timestamp - 102
record(2) -> timestamp - 202
record(3) -> timestamp - 203
max_value() = 4 (assuming max_value() is called at current timestamp 202)
max_value() = 3 (assuming max_value() is called at current timestamp 203)

Any suggestions to improve time complexity than O(n) are welcomed

Comments (4)