60. OA - Amazon Transaction Logs

Amazon Transaction Logs
Your Amazonian team is responsible for maintaining a monetary transaction service. The transactions are tracked in a log file.

A log file is provided as a list of strings where each entry represents a transaction to service. Each transaction consists of:

  • sender_user_id: Unique identifier for the user that initiated the transaction. It consists of only digits with at most 9 digits.
  • recipient_user_id: Unique identifier for the user that is receiving the transaction. It consists of only digits with at most 9 digits.
  • amount_of_transaction: The amount of the transaction. It consists of only digits with at most 9 digits.

The values are separated by a space. For example: "sender_user_id recipient_user_id amount_of_transaction".

Users that perform an excessive amount of transactions might be abusing the service, so you have been tasked to identify the users that have a number of transactions over a threshold. The list of user ids should be ordered in ascending numeric value.

Counting Rule: Each log entry contributes:

  • +1 transaction for the sender user id
  • +1 transaction for the recipient user id
  • If the sender and recipient are the same user id, it counts as only 1 transaction for that user (not 2).

Method Signature

Implement the following method:

public List<String> processLogs(List<String> logs, int threshold)

Parameters

  • logs: list of transaction log strings
  • threshold: the minimum number of transactions a user must have to be included

Returns

  • List<String>: user ids (as strings) with transaction count ≥ threshold, sorted in ascending order by numeric value

Examples

Example 1

logs = Arrays.asList("88 99 200", "88 99 300", "99 32 100", "12 12 15");
threshold = 2;

processLogs(logs, threshold) = Arrays.asList("88", "99");

Transaction counts (sender/recipient both count; self-transaction counts once): 99 - 3, 88 - 2, 12 - 1, 32 - 1. Users with at least 2 transactions are 88 and 99, returned in numeric ascending order.

Example 2

logs = Arrays.asList("1 2 50", "2 3 70", "3 1 20");
threshold = 2;

processLogs(logs, threshold) = Arrays.asList("1", "2", "3");

Each user appears in two transactions total (across sender/recipient roles), so all three meet the threshold.

Example 3

logs = Arrays.asList("10 10 5", "10 10 6", "10 11 7");
threshold = 3;

processLogs(logs, threshold) = Arrays.asList("10");

The two self-transactions each add only 1 to user 10, plus one more transaction where 10 sends to 11. So 10 has 3 total and qualifies; 11 has 1 and does not.

Example 4

logs = Arrays.asList("999999999 1 1", "1 2 1", "2 3 1", "3 1 1");
threshold = 2;

processLogs(logs, threshold) = Arrays.asList("1", "2", "3");

User 999999999 appears only once. Users 1, 2, 3 each appear at least twice. Sorting is by numeric value, so "1" comes before "2" before "3".

Example 5

logs = Arrays.asList("9 10 100", "10 11 100", "11 12 100", "12 9 100");
threshold = 2;

processLogs(logs, threshold) = Arrays.asList("9", "10", "11", "12");

This forms a cycle; each user appears exactly twice (once as sender and once as recipient), so all qualify.

Constraints

  • 1 ≤ n ≤ 10^5 where n is logs.size()
  • 1 ≤ threshold ≤ n
  • Each log entry contains three tokens separated by spaces: sender_user_id recipient_user_id amount_of_transaction
  • The sender_user_id, recipient_user_id, and amount_of_transaction contain only characters in the range ascii['0'-'9'].
  • The sender_user_id, recipient_user_id, and amount_of_transaction start with a non-zero digit.
  • 0 < length of sender_user_id, recipient_user_id, amount_of_transaction ≤ 9
  • The result will contain at least one element.




Please use Laptop/Desktop or any other large screen to add/edit code.