Closed MuhammadTausif closed 1 hour ago
public boolean findTriplet(int[] arr) {
Map<Integer, Integer>mp = new HashMap<>();
for(int i=0;i<arr.length;i++){
mp.put(arr[i], i);
}
for(int i=0;i<arr.length-1;i++){
for(int j=i+1;j<arr.length;j++){
int s=0;
s=arr[i]+arr[j];
if(mp.containsKey(s)){
return true;
}
}
}
return false;
}
Triplet Family
Link
Difficulty: Basic
Given an array arr of integers. Find whether three numbers are such that the sum of two elements equals the third element.
Example:
Expected Time Complexity: O(n2) Expected Auxilary Space: O(1)
Constraints: