# Subarrays with XOR ‘K’

## Problem Statement

\
No of Subarrays count with Xor  = k

## Intuition

```
Approach:

     xor
---------
4 2 2 4 6
     k
x _______
Take running xor

x^k = xor then xor ^ k = x we do this 
```

### Links

<https://www.codingninjas.com/studio/problems/subarrays-with-xor-k_6826258?utm_source=striver&utm_medium=website&utm_campaign=a_zcoursetuf&count=25&page=9&search=&sort_entity=order&sort_order=ASC&leftPanelTabValue=PROBLEM>

### Video Links

<https://www.youtube.com/watch?v=eZr-6p0B7ME&ab_channel=takeUforward>

### Approach 1:

```
```

{% code title="C++" lineNumbers="true" %}

```cpp
#include<bits/stdc++.h>

int subarraysWithSumK(vector < int > arr, int b) {
    int n = arr.size();
    int count = 0, x = 0;
    // xor, count;
    unordered_map<int,int> mp;

    for(int i=0; i<n; i++){
        x ^= arr[i];
        if(x == b)
            count++;

        if(mp.find(x^b) != mp.end()){
            count += mp[x^b];
        } 

        // if(mp.find(x^b) == mp.end()){
            mp[x]++;
        // }
    }

    return count;
}
```

{% endcode %}

### Approach 2:

```
```

{% code title="C++" lineNumbers="true" %}

```cpp
```

{% endcode %}

### Approach 3:

```
```

{% code title="C++" lineNumbers="true" %}

```cpp
```

{% endcode %}

### Approach 4:

```
```

{% code title="C++" lineNumbers="true" %}

```cpp
```

{% endcode %}

### Similar Problems

###


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://coding-9.gitbook.io/untitled/array/medium/subarrays-with-xor-k.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
