`{"id":"ada14afb-82a3-49bd-8e9d-2b3f4c61d46c","name":"Triplets - 1","description":"1. You are given an array(arr) of N numbers.\r\n2. You have to select three indices i,j,k following this condition -> \r\n 0 <= i < j <= k < arr.length\r\n3. Two numbers X and Y as defined as :\r\n X = arr[i] ^ arr[i+1] ^ ... ^ arr[j - 1]\r\n Y = arr[j] ^ arr[j+1] ^ ... ^ arr[k]\r\n4. You have to print the number of triplets where X is equal to Y.","inputFormat":"A number N\r\narr1\r\narr2..\r\nn numbers","outputFormat":"Check the sample ouput and question video.","constraints":"1 &lt;= N &lt;= 1000\r\n0 &lt;= arr[i] &lt;= 10^9\r\n","sampleCode":{"cpp":{"code":"#include <bits/stdc++.h>\nusing namespace std;\nvoid solution(vector<int> &arr){\n // write your code here\n}\n\nint main() {\n\tint n = 0;\n\tcin>>n;\n vector<int> arr(n);\n for(int i = 0 ; i < arr.size(); i++){\n cin>>arr[i];\n }\n solution(arr);\n return 0;\n}"},"java":{"code":"import java.io.*;\r\nimport java.util.*;\r\n\r\npublic class Main {\r\n\r\n\tpublic static void solution(int[] arr){\r\n\t\t//write your code here\r\n\t\t\r\n }\r\n\tpublic static void main(String[] args) {\r\n\t\tScanner scn = new Scanner(System.in);\r\n\t\tint n = scn.nextInt();\r\n int[] arr = new int[n];\r\n for(int i = 0 ; i < arr.length; i++){\r\n arr[i] = scn.nextInt();\r\n }\r\n solution(arr);\r\n }\r\n\t\r\n\t\r\n}"},"python":{"code":""}},"points":10,"difficulty":"easy","sampleInput":"3\r\n1 2 3","sampleOutput":"2","questionVideo":"https://www.youtube.com/embed/sdJBPdoD3OY?end=97","hints":[],"associated":[],"solutionSeen":false,"tags":[],"meta":{"path":[{"id":0,"name":"home"},{"id":"0c54b191-7b99-4f2c-acb3-e7f2ec748b2a","name":"Data Structures and Algorithms","slug":"data-structures-and-algorithms","type":0},{"id":"f3e3dbef-d2b7-4f6d-b357-2ef3738e6c91","name":"Bit Manipulation For Intermediate","slug":"bit-manipulation-for-intermediate-9995","type":0},{"id":"f0dc3459-8624-422d-a3ea-f2177fe79dde","name":"Triplets - 1","slug":"triplets-1","type":1}],"next":{"id":"16d6b399-8322-4333-9a57-ddacebc55564","name":"Triplets-1 MCQ","type":0,"slug":"triplets-1-mcq"},"prev":{"id":"e5b6bbf8-6593-43b2-83f7-9b4670f12fa7","name":"All Repeating Three Times Except One","type":3,"slug":"all-repeating-three-times-except-one"}}}`

# Triplets - 1

1. You are given an array(arr) of N numbers. 2. You have to select three indices i,j,k following this condition -> 0 <= i < j <= k < arr.length 3. Two numbers X and Y as defined as : X = arr[i] ^ arr[i+1] ^ ... ^ arr[j - 1] Y = arr[j] ^ arr[j+1] ^ ... ^ arr[k] 4. You have to print the number of triplets where X is equal to Y.

`{"id":"ada14afb-82a3-49bd-8e9d-2b3f4c61d46c","name":"Triplets - 1","description":"1. You are given an array(arr) of N numbers.\r\n2. You have to select three indices i,j,k following this condition -> \r\n 0 <= i < j <= k < arr.length\r\n3. Two numbers X and Y as defined as :\r\n X = arr[i] ^ arr[i+1] ^ ... ^ arr[j - 1]\r\n Y = arr[j] ^ arr[j+1] ^ ... ^ arr[k]\r\n4. You have to print the number of triplets where X is equal to Y.","inputFormat":"A number N\r\narr1\r\narr2..\r\nn numbers","outputFormat":"Check the sample ouput and question video.","constraints":"1 &lt;= N &lt;= 1000\r\n0 &lt;= arr[i] &lt;= 10^9\r\n","sampleCode":{"cpp":{"code":"#include <bits/stdc++.h>\nusing namespace std;\nvoid solution(vector<int> &arr){\n // write your code here\n}\n\nint main() {\n\tint n = 0;\n\tcin>>n;\n vector<int> arr(n);\n for(int i = 0 ; i < arr.size(); i++){\n cin>>arr[i];\n }\n solution(arr);\n return 0;\n}"},"java":{"code":"import java.io.*;\r\nimport java.util.*;\r\n\r\npublic class Main {\r\n\r\n\tpublic static void solution(int[] arr){\r\n\t\t//write your code here\r\n\t\t\r\n }\r\n\tpublic static void main(String[] args) {\r\n\t\tScanner scn = new Scanner(System.in);\r\n\t\tint n = scn.nextInt();\r\n int[] arr = new int[n];\r\n for(int i = 0 ; i < arr.length; i++){\r\n arr[i] = scn.nextInt();\r\n }\r\n solution(arr);\r\n }\r\n\t\r\n\t\r\n}"},"python":{"code":""}},"points":10,"difficulty":"easy","sampleInput":"3\r\n1 2 3","sampleOutput":"2","questionVideo":"https://www.youtube.com/embed/sdJBPdoD3OY?end=97","hints":[],"associated":[],"solutionSeen":false,"tags":[],"meta":{"path":[{"id":0,"name":"home"},{"id":"0c54b191-7b99-4f2c-acb3-e7f2ec748b2a","name":"Data Structures and Algorithms","slug":"data-structures-and-algorithms","type":0},{"id":"f3e3dbef-d2b7-4f6d-b357-2ef3738e6c91","name":"Bit Manipulation For Intermediate","slug":"bit-manipulation-for-intermediate-9995","type":0},{"id":"f0dc3459-8624-422d-a3ea-f2177fe79dde","name":"Triplets - 1","slug":"triplets-1","type":1}],"next":{"id":"16d6b399-8322-4333-9a57-ddacebc55564","name":"Triplets-1 MCQ","type":0,"slug":"triplets-1-mcq"},"prev":{"id":"e5b6bbf8-6593-43b2-83f7-9b4670f12fa7","name":"All Repeating Three Times Except One","type":3,"slug":"all-repeating-three-times-except-one"}}}` Editor

# Triplets - 1

easy

1. You are given an array(arr) of N numbers. 2. You have to select three indices i,j,k following this condition -> 0

## Constraints

1 <= N <= 1000 0 <= arr[i] <= 10^9

## Format

### Input

A number N arr1 arr2.. n numbers

### Output

Check the sample ouput and question video.

## Example

Sample Input

```.css-23h8hz{color:inherit;font-size:0.875rem;line-height:1.125rem;letter-spacing:0.016rem;font-weight:var(--chakra-fontWeights-normal);white-space:pre-wrap;}3 1 2 3```

### Sample Output

`.css-3oaykw{color:var(--chakra-colors-active-primary);font-size:0.875rem;line-height:1.125rem;letter-spacing:0.016rem;font-weight:var(--chakra-fontWeights-normal);white-space:pre-wrap;font-family:Monospace;}2`

Question Video

Discussions

Show Discussion

Related Resources 