Skip to content

Practice Find X Value of Array II

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

Hard#3525
LeetCode Problem

Find X Value of Array II

Problem Statement

Process queries [index, value, start, x] on nums in order. First update nums[index] to value; this update persists. For that query only, consider the suffix beginning at start and count its nonempty prefixes whose product has remainder x modulo k. Equivalently, remove the prefix before start and then choose a suffix to discard while leaving at least one entry. Removing an empty suffix is allowed. Return one count per query.

Source: Find X Value of Array II on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

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

# Example 2

Input
nums = [1,2,4,8,16,32], k = 4, queries = [[0,2,0,2],[0,2,0,1]]
Output
[1,0]

# Example 3

Input
nums = [1,1,2,1,1], k = 2, queries = [[2,1,0,1]]
Output
[5]

Constraints

1 <= nums[i] <= 10^9
1 <= nums.length <= 10^5
1 <= k <= 5
1 <= queries.length <= 2 * 10^4
queries[i] == [indexi, valuei, starti, xi]
0 <= indexi <= nums.length - 1
1 <= valuei <= 10^9
0 <= starti <= nums.length - 1
0 <= xi <= k - 1

Related LeetCode Problems

Practice more problems similar to Find X Value of Array II.

Review your practice with PhantomCodeAI

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