mediumArrayHash TableHeap Priority QueueSimulationSorting 0 views

Mark Elements on Array by Performing Queries

You are given a 0-indexed array nums of size n consisting of positive integers.

You are given a 0-indexed array nums of size n consisting of positive integers.

You are also given a 2D array queries of size m where queries[i] = [indexi, ki].

Initially all elements of the array are unmarked.

You need to apply m queries on the array in order, where on the ith query you do the following:

Return an array answer of size m where answer[i] is the sum of unmarked elements in the array after the ith query.

Example 1

Input: nums = [1,2,2,1,2,3,1], queries = [[1,2],[3,3],[4,2]]

Output: [8,3,0]

Explanation: We do the following queries on the array:

Example 2

Input: nums = [1,4,2,3], queries = [[0,1]]

Output: [7]

Explanation: We do one query which is mark the element at index 0 and mark the smallest element among unmarked elements. The marked elements will be nums = [ 1 ,4, 2 ,3] , and the sum of unmarked elements is 4 + 3 = 7 .

Constraints

  • n == nums.length
  • m == queries.length
  • 1 <= m <= n <= 10^5
  • 1 <= nums[i] <= 10^5
  • queries[i].length == 2
  • 0 <= indexi, ki <= n - 1

Hints

Companies

No companies reported yet.

Discussion

Sign in to join the discussion.

Loading discussion...

Test results

No test cases yet.