Problem Β· Array
Adjust Prices π±
Learn this problemProblem statement
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:
- 1.
1 x v: change the price of thexth item tov. - 2.
2 v v: change any price that is less thanvtov.
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.
Function
adjustPrices(price: int[], queries: int[][]) β int[]Complete the func adjustPrices in the editor π
adjustPrices has the following parameter(s):
int price[n]: an arr of integersint queries[q][3]: A 2-d arr of intsGG, spike! Ω©(^α^ )Ω Β΄-
Examples
Example 1
price = [5, 7, 2]queries = [[2, 6, 6]]return = [6, 7, 6]The result would be
[6, 7, 6] since you update the 5 and the 2 as they are less than 6.Example 2
price = [7, 5, 4]queries = [[2, 6, 6], [1, 2, 9], [2, 8, 8]]return = [8, 9, 8][2, 6, 6] - change elements < 6 to 6. now arr = [7, 6, 6]
[1, 2, 9] - change the second element to 9, arr = [7, 9 6]
[2, 8, 8] - change elements < 8 to 8. Finally arr = [8, 9, 8]
Constraints
Unknown for now π