As reported: JPMorgan Chase SWE 3 cohort hiring online assessment (Oct 2025), question 2: an array with queries
[L, R]; each query flips the sign of all elements fromLtoR; return the final array.
You are given an integer array nums and a list of queries, where queries[i] = [l, r]. Each query multiplies every element nums[l], nums[l+1], …, nums[r] by −1. Apply all queries in order and return the final array.
Example 1
nums = [1,-2,3,4,-5], queries = [[0,2],[1,4]] -> [-1,-2,3,-4,5]
After [0,2]: [-1,2,-3,4,-5]. After [1,4]: [-1,-2,3,-4,5].
Example 2
nums = [5,6,7], queries = [[0,2],[0,2],[1,1]] -> [5,-6,7]
Clarifications
- Indices are 0-based and both ends are inclusive.
- Zero stays zero.
Constraints: 1 ≤ nums.length ≤ 10^5; -10^9 ≤ nums[i] ≤ 10^9; 0 ≤ queries.length ≤ 10^5; 0 ≤ l ≤ r < nums.length.
Code runner format: two lines — nums and queries as JSON arrays. Implement flipRanges(nums, queries); the harness prints the final array.