Company: kotak
Difficulty: medium
Maximum Product Sales Problem Description An e-commerce company sells N products, numbered 1 to N . Every product has so much stock ( 10^9 items) that it never runs out. Q customers arrive one after another. Each customer performs exactly one action: 1 R -- buys one item of every product whose number is in the range [1, R] (both ends included). 2 L -- buys one item of every product whose number is in the range [L, N] (both ends included). 3 C -- searches for the most bought product among the products numbered C or higher. For a search 3 C , look only at the products C, C+1, ..., N and find the largest number of items sold so far for any of them. Report the product with that largest count. If several products share the largest count, report the one whose number is closest to C ; since every candidate is >= C , this is the smallest such product number. A search sees only the purchases made by the customers who arrived before it. (inferred -- the source describes customers arriving one