The Half That Never Shrinks
int a[] = {4, 9, 2, 7};
int best(int l, int r) { // maximum of a[l..r], both ends included
if (l == r) return a[l];
int mid = (l + r) / 2;
return max(best(l, mid), best(mid, r));
}
cout << best(0, 3);
What happens when this runs?
Sign in to answer questions and track your progress
Sign In