Data Center Peak Hours

Medium2s max execution

You're working at a data center that tracks server load throughout the day. You need to identify the "peak hours" - the period of consecutive hours with the highest average load.

📊 Server Load Analysis:

  1. Input format:
    • An array of 24 numbers representing server load for each hour (0-23)
    • A number K representing how many consecutive hours to analyze
  2. Requirements:
    • Find the start hour (0-23) of the K consecutive hours with highest average load
    • If multiple periods have the same average, return the earliest start hour
    • The period can wrap around midnight (e.g., 23:00-01:00 for K=3)

💡 Example:

For loads [1,2,3,4,5,2,1,2,5,5,4,3] (first 12 hours shown) and K=3:

  • Hours 3-5: (4+5+2)/3 = 3.67
  • Hours 8-10: (5+5+4)/3 = 4.67
  • Return 8 (start of highest average period)

🎯 Your Task:

Complete the solve method that finds the start hour of the peak period. Remember to handle wrapping around midnight!

Examples:

Input: [[1,2,3,4,5,2,1,2,5,5,4,3,2,2,1,1,1,2,3,4,5,3,2,1], 3]
Output: 8

Hours 8-10 (5,5,4) have the highest average of 4.67

Input: [[1,1,1,1,2,2,3,3,2,2,1,1,1,1,1,1,1,1,1,1,1,1,1,2], 4]
Output: 5

Hours 5-8 (2,3,3,2) have the highest average of 2.5

Input: [[3,2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,3], 2]
Output: 22

Hours 22-23 wrap around to next day, [2,3] has highest average

Constraints:

  • •loads.length = 24
  • •0 ≤ loads[i] ≤ 1000
  • •1 ≤ k ≤ 24
  • •All loads are integers
  • •Array always contains exactly 24 hours
TypeScript solution with full type checking
Loading...

Custom Test Input

Output

Run your code to see output...