Closest Tracked Price for Price Drop Alert Queries

Last updated: November 29, 2026

Quick Overview

Implement a structure that supports adding a historical price point for a product and querying the tracked price closest to a target (ties go to the lower price). Both operations should be faster than linear.

Flipkart
Coding & Algorithms
Software Engineer
Flipkart
November 29, 2026
Software Engineer
Onsite
Coding & Algorithms
Medium

0

0

0 solved


Implement a structure that supports adding a historical price point for a product and querying the tracked price closest to a target (ties go to the lower price). Both operations should be faster than linear.

Comes up in Flipkart onsite rounds around the price tracking and 'notify me when the price drops' feature. The interviewer checks that you reach for an ordered structure, use floor and ceiling lookups correctly, and discuss balanced trees versus sorted arrays.

What the Interviewer Expects
  • Identify floor and ceiling queries on an ordered set
  • Use binary search (bisect) on a sorted container, or a balanced BST
  • Handle ties and the empty structure
  • State the costs of insert and query
  • Mention that Python's list insert is O(n) and what to use in production
Key Topics to Cover
ordered set
binary search
floor and ceiling
balanced BST
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
  • How would you support deleting a price point?
  • How would you answer 'how many tracked prices fall within a range'?
  • What would you use in Java or C++ for this?
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
  • add(price): record a price point (duplicates ignored).
  • closest(target): return the tracked price minimizing |p - target|, lower price on ties, None if empty.
  • Many more queries than inser...
High-Level Design

The closest value to a target is either its floor (largest value <= target) or its ceiling (smallest value >= target). An ordered structure gives both in O(log n). In Python, keep a sorted lis...


Submit Your Answer
Markdown supported

Related Questions