Skip to content

Practice Mark Elements on Array by Performing Queries

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Medium#3080
LeetCode Problem

Mark Elements on Array by Performing Queries

Problem Statement

Initially every entry of nums is unmarked. Process queries [index, k] in order. First mark nums[index] if it is not already marked. Then mark up to k of the remaining unmarked entries with the smallest values, breaking equal-value ties by smaller index. If fewer than k remain, mark all of them. Return the sum of the still-unmarked values after each query.

Source: Mark Elements on Array by Performing Queries on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

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

# Example 2

Input
nums = [1,4,2,3], queries = [[0,1]]
Output
[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

Related LeetCode Problems

Practice more problems similar to Mark Elements on Array by Performing Queries.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.