Google Cloud Professional Cloud Developer — Question 75
You are parsing a log file that contains three columns: a timestamp, an account number (a string), and a transaction amount (a number). You want to calculate the sum of all transaction amounts for each unique account number efficiently.
Which data structure should you use?
Answer options
- A. A linked list
- B. A hash table
- C. A two-dimensional array
- D. A comma-delimited string
Correct answer: B
Explanation
A hash table is ideal for this scenario because it allows for fast lookups and updates, making it easy to aggregate transaction amounts by unique account numbers. In contrast, a linked list would be inefficient for this purpose as it does not provide quick access to elements, a two-dimensional array lacks the flexibility for dynamic keys, and a comma-delimited string does not structure data in a way that supports efficient calculations.