FastPrepK-Second Message Suppression

K-Second Message Suppression

Microsoft logoMicrosoft● EasyFULLTIMEONSITE INTERVIEW
Learn

Problem statement

For each chronological (timestamp, message) pair, return whether the message is accepted. The same message may be accepted again only when at least k seconds have passed since its most recent accepted occurrence.

A suppressed occurrence does not reset the timer.

Function

shouldAcceptMessages(timestamps: int[], messages: String[], k: int) → boolean[]

Examples

Example 1

timestamps = [1,2,3,8,11]messages = ["a","b","a","a","a"]k = 10return = [true,true,false,false,true]

The final a is ten seconds after the first accepted a.

Example 2

timestamps = [1,1]messages = ["x","y"]k = 5return = [true,true]

Different messages are independent.

Constraints

  • The arrays have equal length up to 100000.
  • Timestamps are non-decreasing.
  • 0 <= k <= 10^9.

Source note: Author-written prompt excerpt retained for source fidelity.

More Microsoft problems

See Microsoft hiring insights
public boolean[] shouldAcceptMessages(int[] timestamps, String[] messages, int k) {
    // Write your code here.
}
timestamps[1,2,3,8,11]
messages["a","b","a","a","a"]
k10
expected[true,true,false,false,true]
Checking account…