Tap here to switch tabs
Problem
Submissions

Problem: Minimum Operations to Make Array Modulo Alternating II

Try to solve the Minimum Operations to Make Array Modulo Alternating II problem.

Statement

You are given a 00 indexed integer array nums and an integer k.

In one operation, you can choose any index i and either increment or decrement nums[i] by 11.

The array nums is called modulo alternating if there exist two distinct integers x and y such that:

  • 0≤0 \leq x, y <k< k

  • x ≠\neq y

  • nums[i] % k == x for all even indices i

  • nums[i] % k == y for all odd indices i

Return the minimum number of operations needed to make nums modulo alternating.

Constraints:

  • 1≤1 \leq nums.length ≤105\leq 10^5

  • 1≤1 \leq nums[i] ≤109\leq 10^9

  • 2≤2 \leq k ≤105\leq 10^5

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Minimum Operations to Make Array Modulo Alternating II

Try to solve the Minimum Operations to Make Array Modulo Alternating II problem.

Statement

You are given a 00 indexed integer array nums and an integer k.

In one operation, you can choose any index i and either increment or decrement nums[i] by 11.

The array nums is called modulo alternating if there exist two distinct integers x and y such that:

  • 0≤0 \leq x, y <k< k

  • x ≠\neq y

  • nums[i] % k == x for all even indices i

  • nums[i] % k == y for all odd indices i

Return the minimum number of operations needed to make nums modulo alternating.

Constraints:

  • 1≤1 \leq nums.length ≤105\leq 10^5

  • 1≤1 \leq nums[i] ≤109\leq 10^9

  • 2≤2 \leq k ≤105\leq 10^5