[InterviewBit] Pairs With Given Xor

Pairs With Given Xor

  • Time :
  • Space :
1
2
3
4
5
6
7
8
9
10
int Solution::solve(vector<int> &A, int B) {
int res = 0;
unordered_map<int, int> freq;
for(auto a : A) {
res += freq[a^B];
freq[a]++;
}
return res;
}

Author: Song Hayoung
Link: https://songhayoung.github.io/2022/11/01/PS/interviewbit/pairs-with-given-xor/
Copyright Notice: All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.