Dynamic Weighted Range Scores
Updated
Problem statement
Maintain the integer array nums while processing operations in order. Indices are one-based. Operation [0,index,value] replaces that element. Operation [1,left,right] asks for nums[left] + 2*nums[left+1] + ... + (right-left+1)*nums[right]. Return answers only for queries, in query order.
Weights restart at one for each query, regardless of the global array index.
Function
weightedScores(nums: int[], operations: int[][]) → long[]Examples
Example 1
nums = [2,3,4]operations = [[1,1,3],[0,2,1],[1,2,3]]return = [20,9]The full score is 2+2*3+3*4. After updating index 2 to 1, range 2..3 scores 1+2*4.
Example 2
nums = [-1,2]operations = [[1,2,2],[1,1,1]]return = [2,-1]A one-element query always has weight one.
Constraints
- For this exercise, assume 1 <= nums.length <= 100000 and operations.length <= 100000. Values, including updates, lie between -10^6 and 10^6.
- All operation indices are valid and every query has left <= right. Return signed 64-bit scores.
More Intuit Online Assessment questions
- Employee Promotion OpportunitiesOA · Seen Oct 2026
- Next Pascal Row CoefficientOA · Seen Oct 2026
- Parse Router LogsOA · Seen Oct 2026
- Longest Repeated Letter Block with Adjacent SwapsOA · Seen Oct 2026
- Maximum Square-Free DivisorOA · Seen Oct 2026
- Two Tribes from Taller-Person CountsOA · Seen Oct 2026
- Shortest Path from an Encoded GraphOA · Seen Sep 2026
- Oldest and Youngest EmployeesOA · Seen Sep 2026
- Pressure-Isolation Shutdown OrderOA · Seen Sep 2026
- Submask Sum QueriesOA · Seen Sep 2026
Similar questions at other companies
- Dynamic Wall Building and Range QueryCapital One · OACapital One interview questions
- Dynamic Future PricingOptiver · OAOptiver interview questions
- Longest Subarray with Sum at Most KGoogle · OAGoogle interview questions
- Range Sum Query in a Mutable GridBloomberg LP · ONSITE INTERVIEWBloomberg LP interview questions
- Volunteer Awards: Totals Divisible by KNutanix · ONSITE INTERVIEWNutanix interview questions
- Maximum Game Score with Fixed Forward JumpsStripe · OAStripe interview questions
- Most Visited Sprint MarkerMicrosoft · OAMicrosoft interview questions
- Earliest Time to Schedule a MeetingMathWorks · OAMathWorks interview questions
- Earliest Meeting Start on a 24-Hour ClockIMC Trading · OAIMC Trading interview questions
- Minimum Cost of Every K-Capable Model SetTikTok · OATikTok interview questions