×

Instructions

Please read the instructions carefully before starting the exam.

Once you start the exam, the timer will begin, and you cannot pause it.

Ensure that you complete and submit your code within the given time if the timer is enabled.


Warehouse Inventory Optimisation - Arrays (Difficulty - Medium)


Warehouse Inventory Optimisation

Warehouse Inventory Optimisation

Problem Statement:

A warehouse keeps track of its daily shipments using an inventory tracking system. Each day, the number of items in stock is recorded for analysis. Given an array where each element represents the stock count for a specific day, your task is to answer multiple queries efficiently. Each query involves finding the maximum stock count in a specified range of days.

Task:

Write a function that takes an array of stock counts and a list of queries. Each query specifies a range of days (inclusive) and requires the maximum stock count in that range.

Input:

  • An integer array stocks[] where 1 ≤ length of stocks ≤ 105 and 0 ≤ stocks[i] ≤ 109.
  • A list of queries, where each query is a pair of integers [L, R] representing the range L ≤ R (1-based index).

Output:

For each query, return the maximum stock count in the given range.

Example:

Input:

stocks = [100, 200, 50, 300, 400, 250]
queries = [[1, 3], [4, 6], [2, 5]]
        

Output:

200
400
400
        

Explanation:

  • For range [1, 3] (100, 200, 50), the maximum stock count is 200.
  • For range [4, 6] (300, 400, 250), the maximum stock count is 400.
  • For range [2, 5] (200, 50, 300, 400), the maximum stock count is 400.

Constraints:

  • 1 ≤ L, R ≤ length of stocks
  • 1 ≤ Number of queries ≤ 104

Handle edge cases like small arrays, single-day ranges, and arrays with uniform values.


Time Left:



Processing...

Error:


                

Output:

Test Case Result Input Correct Output Your Output




Submission Result