Delivery Performance Streak
Delhivery places significant emphasis on tracking and improving the performance of its delivery executives (DEs). A crucial metric involves understanding consistent performance or improvement trends. This problem challenges you to quantify 'performance streaks' — how many consecutive previous days a DE's delivery count was less than or equal to their current day's performance. This insight helps managers identify consistent performers or days of significant personal bests, fostering a data-driven approach to performance management.
Implement a function calculatePerformanceStreaks that takes an array of daily delivery counts for a delivery executive. For each day, your function must determine the number of consecutive previous days (including the current day itself) where the delivery count was less than or equal to the current day's count. The result should be an array containing these streak lengths for each corresponding day.
deliveryCounts: number[]
deliveryCounts[i] represents the number of parcels delivered on day i.number[]
answer, where answer[i] is the length of the performance streak ending on day i.deliveryCounts is an empty array, the function should return an empty array [].deliveryCounts contains a single element, the streak for that day is 1.day j must be <= deliveryCounts[i] for all j such that j <= i and deliveryCounts[k] <= deliveryCounts[i] for all k in [j, i]. If a day k within this range has deliveryCounts[k] > deliveryCounts[i], the streak breaks at k+1 and only includes days from k+1 to i (inclusive).Examples
Example 1
Input:
deliveryCounts = [10, 4, 5, 9, 11]
Output:
[1, 1, 2, 3, 5]
Note:
Day 0 (10): No preceding day is <= 10. Streak: 1. Day 1 (4): No preceding day (10) is <= 4. Streak: 1. Day 2 (5): Day 1 (4) is <= 5. Day 0 (10) is > 5, so streak breaks. Streak: 2 (from 4, 5). Day 3 (9): Day 2 (5) is <= 9, Day 1 (4) is <= 9. Day 0 (10) is > 9, so streak breaks. Streak: 3 (from 4, 5, 9). Day 4 (11): Day 3 (9) <= 11, Day 2 (5) <= 11, Day 1 (4) <= 11, Day 0 (10) <= 11. No preceding day breaks the streak. Streak: 5 (from 10, 4, 5, 9, 11).
Example 2
Input:
deliveryCounts = [100, 80, 60, 70, 60, 75, 85]
Output:
[1, 1, 1, 2, 1, 4, 6]
Note:
Day 0 (100): Streak 1. Day 1 (80): Streak 1. Day 2 (60): Streak 1. Day 3 (70): Day 2 (60) <= 70. Streak 2 (60, 70). Day 4 (60): Streak 1. Day 5 (75): Day 4 (60) <= 75, Day 3 (70) <= 75, Day 2 (60) <= 75. Day 1 (80) > 75, so streak breaks. Streak 4 (from 60, 70, 60, 75). Day 6 (85): Day 5 (75) <= 85, Day 4 (60) <= 85, Day 3 (70) <= 85, Day 2 (60) <= 85, Day 1 (80) <= 85. Day 0 (100) > 85, so streak breaks. Streak 6 (from 80, 60, 70, 60, 75, 85).
Example 3
Input:
deliveryCounts = [5, 5, 5, 5]
Output:
[1, 2, 3, 4]
Note:
Each day's count is equal to or greater than the preceding days, extending the streak continuously.
Constraints
1 <= deliveryCounts.length <= 10^50 <= deliveryCounts[i] <= 10^9deliveryCounts will only contain non-negative integers.deliveryCounts.number type is sufficient).Loading editor...