Find users who take part in at least a threshold number of transaction logs

Quick Overview

Count how many transaction logs each user takes part in, as sender or recipient, and return the users who reach a threshold in numeric order. It tests hash map counting, the self-transfer edge case, and sorting numeric ID strings by value.

Find users who take part in at least a threshold number of transaction logs

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: easy

Interview Round: Other

Given an array of transaction logs where each log contains `sender_user_id`, `recipient_user_id` and `amount_of_transaction` separated by spaces, return a list of user IDs that have a number of transactions greater than or equal to `threshold`. The result should be sorted in ascending numeric order. A transaction where sender equals recipient counts as only 1 transaction for that user. ### Function Signature ```python def process_logs(logs: list[str], threshold: int) -> list[str]: ``` ### Rules - Each log is a string `"sender_user_id recipient_user_id amount_of_transaction"` with the three fields separated by spaces. - A log counts as one transaction for its sender and one for its recipient. When the sender and the recipient are the same user, the log counts once for that user. - The amount does not affect the count. - User IDs have no leading zeros, so different IDs have different numeric values. - Return the IDs as strings, sorted by numeric value in ascending order, so `"9"` comes before `"10"`. ### Constraints - `1 <= logs.length <= 10^5` - `1 <= threshold <= logs.length` - `sender_user_id`, `recipient_user_id` and `amount_of_transaction` contain only the digits `0` to `9`. - Each ID and each amount has length between 1 and 9. - The result contains at least one element. ### Examples ```text Input: logs = ["88 99 200","88 99 300","99 32 100","12 12 15"], threshold = 2 Output: ["88","99"] ``` User 88 appears in 2 logs and user 99 in 3. User 32 appears once, and user 12 has a single self-transaction, which counts once. Only 88 and 99 reach the threshold of 2. ```text Input: logs = ["1 2 50","1 7 70","1 3 20","2 2 17"], threshold = 2 Output: ["1","2"] ``` User 1 is in 3 logs. User 2 is the recipient in the first log and has one self-transaction, for a count of 2. Users 7 and 3 each have 1. ```text Input: logs = ["9 10 5","10 9 7","100 9 1"], threshold = 2 Output: ["9","10"] ``` User 9 is in all 3 logs, user 10 in 2 and user 100 in 1. Sorting by numeric value puts `"9"` before `"10"`, which a string sort would reverse.

Overview: Count how many transaction logs each user takes part in, as sender or recipient, and return the users who reach a threshold in numeric order. It tests hash map counting, the self-transfer edge case, and sorting numeric ID strings by value.

PracHub logo
General
Nov 25, 2026
easySoftware EngineerOtherCoding & Algorithms
0
0

Given an array of transaction logs where each log contains sender_user_id, recipient_user_id and amount_of_transaction separated by spaces, return a list of user IDs that have a number of transactions greater than or equal to threshold. The result should be sorted in ascending numeric order. A transaction where sender equals recipient counts as only 1 transaction for that user.

Function Signature

def process_logs(logs: list[str], threshold: int) -> list[str]:

Rules

  • Each log is a string "sender_user_id recipient_user_id amount_of_transaction" with the three fields separated by spaces.
  • A log counts as one transaction for its sender and one for its recipient. When the sender and the recipient are the same user, the log counts once for that user.
  • The amount does not affect the count.
  • User IDs have no leading zeros, so different IDs have different numeric values.
  • Return the IDs as strings, sorted by numeric value in ascending order, so "9" comes before "10" .

Constraints

  • 1 <= logs.length <= 10^5
  • 1 <= threshold <= logs.length
  • sender_user_id , recipient_user_id and amount_of_transaction contain only the digits 0 to 9 .
  • Each ID and each amount has length between 1 and 9.
  • The result contains at least one element.

Examples

Input: logs = ["88 99 200","88 99 300","99 32 100","12 12 15"], threshold = 2
Output: ["88","99"]

User 88 appears in 2 logs and user 99 in 3. User 32 appears once, and user 12 has a single self-transaction, which counts once. Only 88 and 99 reach the threshold of 2.

Input: logs = ["1 2 50","1 7 70","1 3 20","2 2 17"], threshold = 2
Output: ["1","2"]

User 1 is in 3 logs. User 2 is the recipient in the first log and has one self-transaction, for a count of 2. Users 7 and 3 each have 1.

Input: logs = ["9 10 5","10 9 7","100 9 1"], threshold = 2
Output: ["9","10"]

User 9 is in all 3 logs, user 10 in 2 and user 100 in 1. Sorting by numeric value puts "9" before "10", which a string sort would reverse.