Find Two Cloud Invoices That Exactly Cover a Promotional Credit

Last updated: November 29, 2026

Quick Overview

Given a list of Google Cloud invoice amounts (integers, in cents) and a promotional credit value, return the indices of two different invoices whose amounts add up exactly to the credit, or an empty list if none exist.

Google
Coding & Algorithms
Software Engineer
Google
November 29, 2026
Software Engineer
Phone Screen
Coding & Algorithms
Easy

0

0

0 solved


Given a list of Google Cloud invoice amounts (integers, in cents) and a promotional credit value, return the indices of two different invoices whose amounts add up exactly to the credit, or an empty list if none exist.

A classic Google phone screen opener dressed up in a Cloud Billing scenario. The interviewer is checking that you jump from the quadratic pair scan to a single-pass hash map, and that you handle duplicates and the 'same index twice' trap cleanly.

What the Interviewer Expects
  • States the O(n^2) brute force and why it is too slow
  • Uses a single-pass hash map from amount to index
  • Checks for the complement before inserting the current element
  • Handles duplicate amounts and the no-solution case
  • Writes runnable code and traces one example
Key Topics to Cover
Hash Map
Complement Lookup
Arrays
Single Pass
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
  • Return every pair of indices rather than just one; what changes?
  • What if the invoices are already sorted and you must use O(1) extra space?
  • How would you solve it if the list is too large for one machine's memory?
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Practice DSA Problems
Sample Answer
Requirements
  • Input: amounts, a list of integers (may contain duplicates and zeros), and an integer credit.
  • Output: [i, j] with i < j and amounts[i] + amounts[j] == credit, or [].
  • The two indices ...
High-Level Design

The brute force checks all pairs in O(n^2). Instead, walk the list once and remember every amount seen so far in a dictionary that maps amount to its index. For each invoice a at index j, the part...


Submit Your Answer
Markdown supported