FastPrepUsers with a Consecutive ABC Error Pattern

Users with a Consecutive ABC Error Pattern

Indeed logoIndeed● EasyFULLTIMEPHONE SCREEN
Learn

Problem statement

Each row of records is [action,userID], in event order. Return the IDs of users whose own action history contains an error pattern.

For this exercise, assume the error is the fixed consecutive pattern A, B, C after considering only that user's events. Events from other users do not break adjacency. Any unrelated action by the same user breaks a partial match. For example, A, D, B, C does not match.

For this exercise, assume each matching user is returned once, in ASCII lexicographic order. IDs are exact strings, so different leading-zero spellings identify different users. Empty input returns an empty array.

Function

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

Examples

Example 1

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

User 1 has ABC, and user 2 has BCAABC. Both contain the fixed consecutive pattern. User 3 has CA.

Example 2

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

User 1 has AAAB and never reaches C. User 2 has BCCAABC, whose final three actions form ABC. User 3 has CA.

Constraints

  • For this exercise, assume 0 <= records.length <= 500.
  • Each row has exactly two strings. For this exercise, assume its action is one uppercase ASCII letter A through Z, and its user ID has 1 through 10 decimal digits.

More Indeed problems

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