Skip to content

Commit f15d6d0

Browse files
committed
new method added
1 parent 3c8a430 commit f15d6d0

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ TODO: question14.c
2323
- bucket sort
2424
- radix sort for d digit numbers
2525
- find maximum sum subarray from an array
26+
- find triplet that sums to given value using binary search technique
2627

2728
### General Questions
2829

arrays/question15.c

+9-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ Space complexity: O(1)
99
METHOD2:
1010
Sorting and then fixing one number and using two pointers one at 1st position and 1 at last, and checking combinations.
1111
If nothing found fixing the next number and trying again
12-
Time complexity:
12+
Time complexity: O(nlogn) + O(n^2) which is O(n^2)
1313
Best case:O(n^2) worst case
1414
Worst case: O(n)
1515
Space complexity: O(1)
@@ -45,10 +45,18 @@ int main(){
4545

4646
//METHOD2
4747
#include <stdio.h>
48+
#include <stdlib.h>
49+
50+
int compar(void const*a, void const *b){
51+
return (*(int*)a-*(int*)b);
52+
}
4853

4954
int main(){
5055
int a[] = {4,3,6,8,2,1,0,9};
5156
int length = sizeof(a)/sizeof(a[0]);
57+
58+
qsort(a,length,sizeof(int),compar);
59+
5260
int num1, num2, num3,j,k, sum = 10;
5361

5462
for(int i=0; i<length-2;i++){ //as last two will be covered in while loop always for second and third num

0 commit comments

Comments
 (0)