FastPrepMost Accessed Resource in Five Minutes

Most Accessed Resource in Five Minutes

Indeed logoIndeed● MediumFULLTIMEPHONE SCREEN
Learn

Problem statement

Each string in logs is userId,resourceId,timestamp. Find the resource with the most accesses in one five-minute window. Return that resource, its count, and every access timestamp in the selected window.

For this exercise, assume timestamps are nonnegative integer seconds. A window starts at an access timestamp s and includes every access to that resource with s <= timestamp <= s + 300. Repeated entries count separately.

For this exercise, assume ties choose the lexicographically smallest resource, then the earliest window start. Return a string array [resourceId,count,timestamp1,...], with decimal count and ascending timestamps, including duplicates. An empty log returns an empty array.

For this exercise, assume records contain exactly three comma-separated fields without spaces and identifiers are nonempty case-sensitive alphanumeric strings.

Function

busiestWindow(logs: String[]) → String[]

Examples

Example 1

logs = ["u1,b,0","u2,a,0","u3,a,150","u4,a,300","u5,a,301"]return = ["a","3","0","150","300"]

Resource a has three accesses in [0,300]; [150,450] also has three, so the earlier start is selected.

Example 2

logs = ["u,b,10","v,a,20"]return = ["a","1","20"]

Both resources have one access, so lexicographically smaller a wins.

Constraints

  • For this exercise, assume 0 <= logs.length <= 2000.
  • Identifier lengths are from 1 to 30.
  • Timestamps are from 0 through 10^9.

More Indeed problems

See Indeed hiring insights
public String[] busiestWindow(String[] logs) {
    // Write your code here.
    return new String[0];
}
logs["u1,b,0","u2,a,0","u3,a,150","u4,a,300","u5,a,301"]
expected["a", "3", "0", "150", "300"]
Checking account…