Don't know why this code is running

Revision en2, by silenttkillerr, 2023-09-17 04:02:15

I was solving a problem from Leetcode https://leetcode.com/problems/count-pairs-of-points-with-distance-k/

In this problem i am only checking from (i to i+100) and it passed , i not have any proof how pair will exist only till i+100,can anyone provide any proof or intuition.

``` class Solution { public: int countPairs(vector<vector>& coordinates, int k) { int ans=0; int n=coordinates.size(); sort(coordinates.begin(),coordinates.end()); map<int,int>mp; vector<vector>c; int index=0; for(int i=0;i<n;i++) { mp[index]++; c.push_back(coordinates[i]); i++; while(i<n && coordinates[i]==c.back()) { i++; mp[index]++; } i--; index++; } n=c.size(); for(int i=0;i<n;i++) { for(int j=i+1;j<min(n,i+80);j++) { int xr=c[i][0]^c[j][0]; xr+=c[i][1]^c[j][1]; if(xr==k) { ans+=mp[i]*mp[j]; } } } if(k==0) { for(auto x:mp) { ans+=(1LL*x.second*(x.second-1))/2; } } return ans; } };

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en3 English silenttkillerr 2023-09-17 04:03:08 1101
en2 English silenttkillerr 2023-09-17 04:02:15 6 Tiny change: 'ition.\n\nclass So' -> 'ition.\n\n```\nclass So'
en1 English silenttkillerr 2023-09-17 04:01:54 1429 Initial revision (published)