Data Updates
Updated
Problem statement
You are given an integer array data and a list of range updates updates. Each update is a pair [left, right].
An update flips the sign of every value from position left through position right, so each of those values is multiplied by -1. Positions start at 1, and both ends of the range are included.
Apply all the updates and return the final array.
Function
applyDataUpdates(data: int[], updates: int[][]) → int[]Examples
Example 1
data = [1,-2,3,-4]updates = [[1,2],[2,4]]return = [-1, -2, -3, 4]Start with [1, -2, 3, -4].
- The update
[1, 2]flips positions 1 and 2, which gives[-1, 2, 3, -4]. - The update
[2, 4]flips positions 2, 3, and 4, which gives[-1, -2, -3, 4].
Example 2
data = [5,0,-7]updates = [[1,3],[1,3]]return = [5, 0, -7]The same update runs twice, so every value is flipped twice and returns to its start. 0 stays 0.
Example 3
data = [9]updates = [[1,1]]return = [-9]The only position is flipped once, which gives [-9].
Example 4
data = [2,4,6,8,10]updates = [[2,3],[3,4],[5,5]]return = [2, -4, 6, -8, -10]Position 2 is flipped once, position 3 twice, position 4 once, and position 5 once. Position 1 is never touched, and position 3 returns to 6.
Constraints
1 <= data.length <= 10^4-10^9 <= data[i] <= 10^91 <= updates.length <= 10^4updates[i].length == 21 <= updates[i][0] <= updates[i][1] <= data.length
More Expedia Online Assessment questions
- Balanced NumbersOA · Seen Aug 2026
- REST API: Discounted PriceOA · Seen Aug 2026
- Maximum Team SizeOA · Seen Mar 2026
- Per-Domain Request LimiterOA · Seen Oct 2025
- Count Equal-Frequency SubsequencesOA · Seen Mar 2025
- Count Increasing Stock PeriodsOA · Seen Mar 2025
- Get Minimum StepsOA · Seen Oct 2024
- Rank Songs by PopularityOA · Seen Oct 2024
- Calculate the SumOA · Seen Oct 2024
- Get Maximum EfficiencyOA · Seen Oct 2024
Similar questions at other companies
- Online No-Intercept Linear RegressionTwo Sigma · OATwo Sigma interview questions
- Array Challenge (QR Intern)Akuna Capital · OAAkuna Capital interview questions
- Range Negation UpdatesJP Morgan Chase · OAJP Morgan Chase interview questions
- Hall of Shifting TilesAdobe · OAAdobe interview questions
- Prefix Scores With the Running MaximumC3.ai · OAC3.ai interview questions
- Wallet Balance on a Selected DayBharatPe · PHONE SCREEN
- Calculate Server Shutdown PenaltyStripe · PHONE SCREEN · ONSITE INTERVIEWStripe interview questions
- Instrument Stack Language JumpsJane Street · PHONE SCREENJane Street interview questions
- Schedule Buffered Video PlaybackNuro · PHONE SCREENNuro interview questions
- Weighted Lottery WinnersAmazon · ONSITE INTERVIEW
Expedia interview experiences
- Expedia Intern Final Round in 2021: 28 Experiences (Part 4 of 6)
- Expedia Intern Finals Before 2020: 14 Experiences (Part 6 of 6)
- Expedia Intern Final Round in 2020: 24 Experiences (Part 5 of 6)
- Expedia Intern Final Round in 2022: 15 Experiences (Part 3 of 6)
- Expedia Intern Final Round in 2023: 17 Experiences (Part 2 of 6)
- Expedia SWE Intern Final Round: 126 Experiences (Part 1 of 6)