Users with a Consecutive ABC Error Pattern
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
AthroughZ, and its user ID has1through10decimal digits.