Skip to content

Latest commit

 

History

History
26 lines (20 loc) · 679 Bytes

16.md

File metadata and controls

26 lines (20 loc) · 679 Bytes
bool checkTriplet(int arr[], int n) {
	    // code here
	    
	   unordered_map<int,int> m;  //map is used instead of vector so that a, b,c distinct ,
	                               //for handling the case when a2-b2==b2 or a2
	    
	    for(int i=0;i<n;i++)
	        m[pow(arr[i],2)]++;
	        
	   
	   vector<int>v;
	   for(auto it:m)
	    v.push_back(it.first);
	    
	    for(int i=0;i<v.size()-1;i++)
	    {
	        for(int j=i+1;j<v.size();j++)
	            if(m.find(v[i]+v[j])!=m.end() )
	                return true;
	    }
	    return false;
	}