Feature #5: Order Processing Milestones
Explore how to implement a feature to identify days spent at specific Amazon order processing milestones using a binary search algorithm in Go. Learn to analyze cumulative order data presented as milestones, handle cases of skipped milestones, and achieve efficient search with O(log n) time complexity. This lesson sharpens your ability to translate real-world reporting needs into coding challenges relevant in tech interviews.
We'll cover the following...
Description
Let’s assume the Amazon team wants to collect stats of the number of orders processed. These stats will be presented in a quarterly report using a histogram. To collect data for this presentation, the devs have stored the number of orders for each day rounded down to the nearest significant milestone. For example, when we meet or exceed one million orders, we display “1M+ orders processed.” We continue to display the same message until another milestone is reached. For instance, when nine million orders or more are processed, we display “9M+ orders processed.” Every day, the rounded cumulative number of orders processed is appended to an array.
Now, your task is to find out how many days we spent jumping from one milestone to the next. You will be given the array containing the daily milestones. Assume that this array resets each quarter, so we start from 0 million. Let’s say the array is: [0, 1, 1, 2, 2, 2, 3, 4, 4, 4, 5, 5, 6, 7]. This array shows the stats for fourteen days. Now, you will also be given a value representing a certain milestone; suppose it is 4. This means that you need to find in which days the “4M+ orders processed” milestone occurred.
Your feature should return [7, 9], which ...