FastPrepThree Calls Within Three Seconds

Three Calls Within Three Seconds

Bloomberg LP logoBloomberg LP● EasyNEW GRADPHONE SCREENONSITE INTERVIEW
Learn

Problem statement

timestamps are nondecreasing call times in milliseconds. After each call, return whether at least three calls including the current one lie within a window of at most 3000 milliseconds, meaning current time minus the third-most-recent qualifying time is at most 3000.

Function

threeCallsWithinWindow(timestamps: long[]) → boolean[]

Examples

Example 1

timestamps = [0,1000,3000,7000,7500,8000]return = [false,false,true,false,false,true]

Calls 0,1000,3000 fit exactly; later 7000,7500,8000 also fit.

Constraints

  • 0 <= timestamps.length <= 2 * 10^5.
  • Timestamps are nondecreasing.

More Bloomberg LP problems

See Bloomberg LP hiring insights
public boolean[] threeCallsWithinWindow(long[] timestamps) {
  // Write your code here.
}
timestamps[0,1000,3000,7000,7500,8000]
expected[false,false,true,false,false,true]
Checking account…