Skip to content

Commit 142fab2

Browse files
committed
triplet sum - can be updated
1 parent d69f134 commit 142fab2

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
2+
public class TimeAndSpaceComplexityAnalysis_TripletSum {
3+
4+
//inefficient asf. Time limit exceeded error in 2 test cases ;-;
5+
6+
public static int tripletSum(int[] arr, int num) {
7+
//Your code goes here
8+
9+
int count = 0;
10+
11+
for(int i = 0; i<arr.length; i++){
12+
13+
for(int j = i+1; j<arr.length; j++){
14+
15+
for (int k = j+1; k<arr.length; k++){
16+
17+
if ((arr[i] + arr[j] + arr[k])==num){
18+
count++;
19+
}
20+
}
21+
}
22+
}
23+
24+
return count;
25+
}
26+
27+
}

0 commit comments

Comments
 (0)