
Answer-first summary for fast verification
Answer: A hash table
A hash table (option B) is the most efficient data structure for this task. It allows O(1) average time complexity for inserting and updating key-value pairs. Here, the account number can serve as the key, and the cumulative transaction amount as the value. Each time a transaction is parsed, the hash table enables quick lookup to add the amount to the existing total for the account. Other options like linked lists (A) or 2D arrays (C) would require O(n) lookups, and a comma-delimited string (D) would be highly inefficient for dynamic updates.
Author: LeetQuiz Editorial Team
Ultimate access to all questions.
Which data structure is most efficient for calculating the sum of transaction amounts per unique account number when parsing a log file with three columns (timestamp, account number as string, and transaction amount as number)?
A
A linked list
B
A hash table
C
A two-dimensional array
D
A comma-delimited string
No comments yet.