Dark Store Inventory Optimization
Blinkit's rapid delivery model relies heavily on efficient inventory management across its network of local dark stores. Each dark store maintains stock levels for thousands of items. For a critical, fast-moving item, it's crucial to have real-time insights into stock availability and the ability to quickly adjust inventory. This problem simulates a core part of that system, focusing on optimizing operations for a single item across multiple dark stores.
You are tasked with implementing a system to manage the stock levels of a single item across N dark stores. Your system must efficiently handle a sequence of operations:
N dark stores.darkStore[i] += value). This could represent a single sale or a small incoming delivery.darkStore[j...k] += value). This is typical for bulk regional promotions or large-scale incoming deliveries affecting multiple stores.Your function should process all operations and return a list of results for each RANGE_MIN_QUERY operation in the order they appear.
Function Signature:
function processDarkStoreOperations(initialStocks: number[], operations: Array<[number, number, number, number?] | [number, number, number]>): number[]
Parameters:
initialStocks: A number[] representing the initial stock levels for N dark stores. initialStocks[i] is the stock at dark store i.operations: An array of operations to perform. Each operation is an array following one of these formats:
[1, index, valueChange]: Point Stock Adjustment. Adds valueChange to initialStocks[index]. index is 0-based.[2, startIndex, endIndex, valueChange]: Range Stock Adjustment. Adds valueChange to initialStocks[i] for all i such that startIndex <= i <= endIndex. startIndex and endIndex are 0-based and inclusive.[3, startIndex, endIndex]: Range Minimum Stock Query. Returns the minimum stock level among initialStocks[i] for all i such that startIndex <= i <= endIndex. startIndex and endIndex are 0-based and inclusive.Return Value:
number[] containing the results of all RANGE_MIN_QUERY operations, in the order they were processed.0.index, startIndex, endIndex) are 0-based.[startIndex, endIndex]) are inclusive.Examples
Example 1
Input:
initialStocks = [10, 20, 5, 15], operations = [[3, 0, 3], [1, 2, 8], [3, 0, 3], [3, 1, 2]]
Output:
[5, 10, 13]
Note:
Example 2
Input:
initialStocks = [10, 2, 15, 8], operations = [[3, 0, 3], [2, 0, 1, -5], [3, 0, 3], [2, 2, 3, 10], [3, 0, 3], [1, 1, 20], [3, 0, 3]]
Output:
[2, 0, 0, 5]
Note:
Constraints
1 <= N <= 10^5 (number of dark stores)1 <= M <= 10^5 (number of operations)0 <= initialStocks[i] <= 10^9-10^9 <= valueChange <= 10^90 <= index < N0 <= startIndex <= endIndex < NO(M log N).O(N).Loading editor...