Process Logs
Updated
Problem statement
Application logs are useful in analyzing interaction with an application and may also be used to detect suspicious activities.
A log file is provided as a string array where each entry represents a money transfer in the form "sender_user_id recipient_user_id amount". Each of the values is separated by a space.
- sender_user_id and recipient_user_id both consist only of digits, are at most 9 digits long and start with non-zero digit
- amount consists only of digits, is at most 9 digits long and starts with non-zero digit
Logs are given in no particular order. Write a function that returns an array of strings denoting user_id's of suspicious users who were involved in at least threshold number of log entries. The id's should be ordered ascending by numeric value.
Function
processLogs(logs: String[], threshold: int) → String[]
Complete the function processLogs in the editor.
The function has the following parameter(s):
- 1.
String logs[n]: each logs[i] denotes the i’th entry in the logs - 2.
int threshold: the minimum number of transactions that a user must have to be included in the result
Returns
String[]: an array of user id's as strings, sorted ascending by numeric value
Examples
Example 1
logs = ["88 99 200", "88 99 300", "99 32 100", "12 12 15"]threshold = 2return = ["88", "99"]There are two users with at least threshold = 2 transactions: 99 and 88. In ascending order, the return array is ['88', '99'].
Note: In the last log entry, user 12 was on both sides of the transaction. This counts as only 1 transaction for user 12.
Constraints
- 1 ≤ n ≤ 10^5
- 1 ≤ threshold ≤ n
- The sender_user_id, recipient_user_id and amount contain only characters in the range ascii["0"-"9"].
- The sender_user_id, recipient_user_id and amount start with a non-zero digit.
- 0 < length of sender_user_id, recipient_user_id, amount ≤ 9.
- The result will contain at least one element.
More Snowflake interview questions
- Connect Four from the Last MovePHONE SCREEN · Seen Nov 2026
- Minimum Edits to a Perfect Binary TreePHONE SCREEN · Seen Nov 2026
- Parallel Courses IIIONSITE INTERVIEW · Seen Nov 2026
- Safest Shortest Path Through a GridOA · Seen Nov 2026
- Configurable Per-Client Token BucketsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Find Valid SET Card TriplesOA · PHONE SCREEN · Seen Nov 2026
- LFU CacheOA · ONSITE INTERVIEW · Seen Nov 2026
- Minimum Index Distance Between Person and CakeOA · PHONE SCREEN · Seen Nov 2026
- Minimum N-ary Tree Depth DeletionsOA · PHONE SCREEN · Seen Nov 2026
- Sum of Binary Tree Boundary NodesOA · PHONE SCREEN · Seen Nov 2026
Similar questions at other companies
- Count User Mentions in Chat MessagesRamp · OARamp interview questions
- Blood Type Inheritance: Possible Parent GenotypesAbridge · OAAbridge interview questions
- Count Repeated Request IDs (Data Science OA)McKinsey & Company · OAMcKinsey & Company interview questions
- Flat JSON Value DifferencesChubb · OAChubb interview questions
- Get Search ResultsJP Morgan Chase · OAJP Morgan Chase interview questions
- Lexicographic Word FrequenciesUpstart · OAUpstart interview questions
- Email Log Processing, Grouping, and SortingStripe · OAStripe interview questions
- Most Frequent CharacterMicrosoft · OAMicrosoft interview questions
- Get Maximum Information GainAmazon · OA
- Better CompressionGoldman Sachs · OAGoldman Sachs interview questions