Given a list of customer purchase dates, identify customers who have not made a purchase on three consecutive dates.
💡 Model Answer
To solve this problem you can process the data per customer. First, group the purchase records by customer and sort the dates. Then iterate through the sorted list and look for any gap of three or more consecutive days where no purchase occurred. If such a gap exists, the customer is flagged. In SQL you can use window functions: partition by customer, order by date, and compute the difference between the current date and the previous purchase date. A difference of 4 or more days indicates a missing purchase on three consecutive days. You can then group by customer and filter those with at least one such gap. Complexity is O(n log n) for sorting or O(n) if the dates are already sorted. The SQL solution runs in a single scan with window functions, making it efficient for large datasets.
This answer was generated by AI for study purposes. Use it as a starting point — personalize it with your own experience.
🎤 Get questions like this answered in real-time
Assisting AI listens to your interview, captures questions live, and gives you instant AI-powered answers on a discreet on-screen overlay.
Get Assisting AI — Starts at ₹500