what is your favourite data structure?
Anonymous
For the question: Find all pairs that sum up to a given no x: 1. Sort the array using quick sort O(nlogn) 2. See code, call with allPairs (a, 0, a.length - 1); {{{ void allPairs (int a[], int l, int r, int x) { if(a[l] + a[r] == x) print("%d %d", a[l], a[r]); else if (a[l] + a[r] > x) allPairs(a, l, r-1, x); else allPairs(a, l+1, r, x); }
Check out your Company Bowl for anonymous work chats.