1442. Count Triplets That Can Form Two Arrays of Equal XOR Medium
1/**
2 * [1442] Count Triplets That Can Form Two Arrays of Equal XOR
3 *
4 * Given an array of integers arr.
5 * We want to select three indices i, j and k where (0 <= i < j <= k < arr.length).
6 * Let's define a and b as follows:
7 *
8 * a = arr[i] ^ arr[i + 1] ^ ... ^ arr[j - 1]
9 * b = arr[j] ^ arr[j + 1] ^ ... ^ arr[k]
10 *
11 * Note that ^ denotes the bitwise-xor operation.
12 * Return the number of triplets (i, j and k) Where a == b.
13 *
14 * Example 1:
15 *
16 * Input: arr = [2,3,1,6,7]
17 * Output: 4
18 * Explanation: The triplets are (0,1,2), (0,2,2), (2,3,4) and (2,4,4)
19 *
20 * Example 2:
21 *
22 * Input: arr = [1,1,1,1,1]
23 * Output: 10
24 *
25 *
26 * Constraints:
27 *
28 * 1 <= arr.length <= 300
29 * 1 <= arr[i] <= 10^8
30 *
31 */
32pub struct Solution {}
33
34// problem: https://leetcode.com/problems/count-triplets-that-can-form-two-arrays-of-equal-xor/
35// discuss: https://leetcode.com/problems/count-triplets-that-can-form-two-arrays-of-equal-xor/discuss/?currentPage=1&orderBy=most_votes&query=
36
37// submission codes start here
38
39impl Solution {
40 pub fn count_triplets(arr: Vec<i32>) -> i32 {
41 0
42 }
43}
44
45// submission codes end
46
47#[cfg(test)]
48mod tests {
49 use super::*;
50
51 #[test]
52 fn test_1442() {
53 }
54}
55
Back
© 2025 bowen.ge All Rights Reserved.