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 x v: Change the price of the xth item to v.2 v v: Change any price that is less than v to v.
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.
Complete the function finalPrices in the editor.
finalPrices has the following parameters:
n: an integer, the number of itemsint price[n]: an array of integers representing the pricesq: an integer, the number of queriesint queries[q][3]: a 2D array of price adjustment queries
Returns
int[]: an array of integers representing the final prices
Examples
01 · Example 1
n = 3 price = [7, 5, 4] q = 3 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 2nd element to 9, arr = [7, 9, 6].[2, 8, 8]: Change elements < 8 to 8. Finally arr = [8, 9, 8].
Return [8, 9, 8] as the answer.
More Amazon problems
- Get the Fewest Moves (~Operations~)~Seen Jun 2026
- Create Array Generator ServiceSeen Jun 2026
- Minimum Merge ConflictsOA · Seen Jun 2026
- Get Minimum AmountOA · Seen Jun 2026
- Drone Delivery RouteOA · Seen Jun 2026
- Minimum Operations to Make Array ValidOA · Seen Jun 2026
- Sort Bug Report FrequenciesOA · Seen Jun 2026
- Maximum Equal Parts for PrefixesOA · Seen Jun 2026
public int[] finalPrices(int n, int[] price, int q, int[][] queries) {
// write your code here
}
n3
price[7, 5, 4]
q3
queries[[2, 6, 6], [1, 2, 9], [2, 8, 8]]
expected[8, 9, 8]
sign in to submit