Detect Near-Duplicate Fare Quotes Within Time and Price Windows
Last updated: November 29, 2026
Quick Overview
Given a list of fare quotes in time order, return True if there exist two indices i != j with |i - j| <= k and |fare[i] - fare[j]| <= t. This flags quotes that are suspiciously close in both time and price.
Uber
November 29, 20260
0
0 solved
Given a list of fare quotes in time order, return True if there exist two indices i != j with |i - j| <= k and |fare[i] - fare[j]| <= t. This flags quotes that are suspiciously close in both time and price.
An Uber screen problem tied to fraud and pricing integrity checks on quote streams. It tests sliding windows combined with ordered lookup or bucketing, and whether you can beat O(n*k).
What the Interviewer Expects
- Maintains a window of the last k fares
- Uses buckets of width t + 1 so each bucket holds at most one fare
- Checks the same bucket and the two neighbors
- Evicts the fare that leaves the window
- States O(n) time and O(k) space, and contrasts with an ordered set at O(n log k)
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
- Solve it with a balanced BST or sorted list and compare.
- How would this run on an unbounded stream per rider?
- What if t is a percentage of the fare rather than an absolute amount?
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: integer list
fares, windowk >= 0, tolerancet >= 0. - Output: True if any pair within k positions differs by at most t.
- Fares can be negative after adjustments, so bucket math must h...
High-Level Design
An ordered set of the last k fares works: for each new fare find the smallest value >= fare - t and check it is <= fare + t. A faster approach uses buckets of width w = t + 1. Two fares in the s...