MCPcopy Create free account
hub / github.com/Tiwarishashwat/InterviewCodes / find3Numbers

Method find3Numbers

TripletSum.java:5–22  ·  view source on GitHub ↗
(int A[], int n, int X)

Source from the content-addressed store, hash-verified

3 //Function to find if there exists a triplet in the
4 //array A[] which sums up to X.
5 public static boolean find3Numbers(int A[], int n, int X) {
6
7 // Your code
8 for(int i=0;i<n-2;i++)
9 {
10 HashSet<Integer> set = new HashSet<>();
11 int toFind=X-A[i];
12 for(int j=i+1;j<n;j++)
13 {
14 if(set.contains(toFind-A[j]))
15 {
16 return true;
17 }
18 set.add(A[j]);
19 }
20 }
21 return false;
22 }
23}

Callers

nothing calls this directly

Calls 1

addMethod · 0.45

Tested by

no test coverage detected