Computer Science, asked by shivanigoel77, 5 months ago

Bob has found an array A of size N Now he wants to change the array such that the Bitwise Xor of every K consecutive elements becomes o You need to help Bob find the minimum number of elements he needs to change.

Answers

Answered by titan2218
0

Answer:

Bob has found an array A of size N Now he wants to change the array such that the Bitwise Xor of every K consecutive elements becomes o You need to help Bob find the minimum number of elements he needs to change.

Problem Constraints

• 1 <= K <= N <= 10^4

• O <= A[i] <= 2^10-1

Input Format

Input consists of 2 arguments, first is the vector A and second is k

Output Format

Return a single integer, the minimum number of changes required.

Example Input

Input 1: A = [1, 2, 3, 1] K=3

Input 2: A - [1, 2, 5] K=3

Example Output

Output 1: 0

Output 2: 1

Example Explanation

Explanation 1: Xor of every 3 consecutive elements is already e. No changes required.

Explanation 2: We can change the first element to 7, so the array becomes [7, 2, 5] and Xor of every 3 consecutive elements is now. Hence, number of changes required is 1.

Explanation:

Answered by aryansuts01
0

Answer:

When all the elements in an array are taken, they must create a series that is consecutive.

Explanation:

An array must have a difference between both the greatest and minimum component of exactly n-1 for it to contain consecutive integers. We can verify that each element in the array is unique by adding it into a set or by utilizing a visited array.

1 &lt; =K &lt; =N &lt; =10^4

0 &lt; =A[i] &lt; =2^{10} -1

I / P Format : Two arguments make up the input: the first is the vector A and the second is k.

O / P Format : The least amount of changes necessary should be returned as a single integer.

For Example take an input

Every 3 successive elements' xor already equals e. Nothing needs to change.

Input :

A=[1,2,3,1]K=3

Output :

0

By changing the initial element to 7, the array will become [7, 2, 5], and every third member will now be Xor. Therefore, there are only one alteration needed.

Input :

A = [1, 2, 5] K=3

Output :

1

#SPJ2

Similar questions