FastPrepFirst Three Badge Times per User

First Three Badge Times per User

Wayfair logoWayfair● MediumFULLTIMEPHONE SCREEN
Learn

Problem statement

Each row of records is [userID,timestamp,action], recording either clockin or clockout. Return the first three times for every represented user, or all of that user's times if they have fewer than three.

For this exercise, assume first means the earliest numeric timestamps, regardless of input order. Both actions count. Every occurrence counts separately, including identical rows or events with equal timestamps. No matching or alternating action sequence is required.

For this exercise, assume the result contains one row [userID,time1,...] per user. Treat IDs as complete case-sensitive strings, so different leading-zero spellings identify different users. Sort rows by ASCII user ID and selected times numerically ascending. Serialize times as canonical decimals without leading zeros. Empty input returns an empty array.

Function

firstThreeTimes(records: String[][]) → String[][]

Examples

Example 1

records = [["A","1","clockin"],["B","2","clockout"],["C","3","clockin"]]return = [["A","1"],["B","2"],["C","3"]]

Each represented user has only one event; both action types contribute a timestamp.

Example 2

records = [["Ada","9","clockout"],["Ben","4","clockin"],["Ada","3","clockin"],["Ada","3","clockout"],["Ada","1","clockin"],["Ben","2","clockout"]]return = [["Ada","1","3","3"],["Ben","2","4"]]

Ada has four records, so keep 1,3,3. Ben has two and retains both 2,4. Rows are ordered by user ID.

Constraints

  • For this exercise, assume 0 <= records.length <= 200. Each row has exactly three strings.
  • For this exercise, assume user IDs contain 1 through 30 ASCII letters, digits or underscores. IDs are case-sensitive.
  • For this exercise, assume timestamps have 1 through 10 decimal digits, may have leading zeros, and have values from 0 through 1000000000. Actions are clockin or clockout; fields contain no whitespace.

More Wayfair problems

See Wayfair hiring insights
public String[][] firstThreeTimes(String[][] records) {
    // Write your code here.
    return new String[0][];
}
records[["A","1","clockin"],["B","2","clockout"],["C","3","clockin"]]
expected[["A", "1"], ["B", "2"], ["C", "3"]]
Checking account…