Count Trip Pairs Whose Fares Exactly Match a Promo Credit
Last updated: November 29, 2026
Quick Overview
Given an array of trip fares in cents and a promo credit value, count the number of index pairs i < j whose fares sum exactly to the credit, so finance can estimate how many riders could fully spend a two-trip promotion.
Uber
November 29, 20260
0
0 solved
Given an array of trip fares in cents and a promo credit value, count the number of index pairs i < j whose fares sum exactly to the credit, so finance can estimate how many riders could fully spend a two-trip promotion.
A warm-up in Uber technical screens that checks whether you can move from the O(n^2) brute force to a one-pass hash map count without over-engineering. Interviewers listen for whether you count pairs (including duplicates) rather than just detecting existence.
What the Interviewer Expects
- State the brute force and its cost first
- Use a frequency map of fares seen so far
- Count all pairs, including repeated equal fares
- Keep the solution to one pass
- Mention integer cents to avoid float equality issues
Key Topics to Cover
How to Approach This
- Clarify input constraints and edge cases before writing code.
- Walk through your approach verbally and confirm with the interviewer before coding.
- Start with a brute force solution, then optimize. Mention time and space complexity.
- Test your solution with examples, including edge cases like empty input or duplicates.
- Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
- Return the pairs themselves instead of the count; what changes in output size?
- What if the array is already sorted and memory is tight?
- How would you count triples summing to the credit?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
- Input: list
faresof non-negative integers (cents), integercredit. - Output: number of pairs
(i, j)withi < jandfares[i] + fares[j] == credit. - Equal fares at different indices are di...
High-Level Design
For each fare f, the partners that complete it are exactly the earlier fares equal to credit - f. If we keep a frequency map of fares seen so far, each step adds seen[credit - f] to the answer a...