Message on Whatsapp 8879355057 for DSA(OA + Interview) + Fullstack Dev Training + 1-1 Personalized Mentoring to get 10+LPA Job
0 like 0 dislike
833 views
in Online Assessments by Expert (46,090 points) | 833 views

1 Answer

0 like 0 dislike

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)

by Expert (46,090 points)