I received this question in the Hackerrank and was able to solve it naively but not able to optimize it. Some of the test cases gave me TLE.
Question:
A general store at hackerland sells n items with the price of the ith item represented by price[i]. The store adjusts the price of the items based on inflation as queries of two types:
Given an array price of n integers and the price adjustment queries are in the form of a 2-d array where query[i] consists of 3 integers, find the final prices of all the items**
For example, price = [5, 7, 2], queries = [[2, 6, 6]] so the result would be [6, 7, 6] since you update the 5 and the 2 as they are less than 6
How would you optimize the second query type so you don't have to loop through the list each time when updating the values?