Warning: count(): Parameter must be an array or an object that implements Countable in /home/customer/www/thegatebook.in/public_html/qa/qa-include/qa-theme-base.php on line 177

# DSA - Grand Test -Q15

Warning: count(): Parameter must be an array or an object that implements Countable in /home/customer/www/thegatebook.in/public_html/qa/qa-include/qa-theme-base.php on line 177

Consider the following program:

`int foo(int *p, int n){`

`   if( n <= 1) return 1;`

`   else `

`     return max(bar(p+1,n-1),p + p);`

`}`

`int bar (int *p, int n){`

`   if(n <= 1) return 1;`

`   else `

`     return min(foo(p+1, n-1), p-p;`

`}`

`int main(){`

`   int a[] = {8,9,5,9,10};`

`   printf("\n %d", foo(a,5));`

`   return 0;`

`}`

Note: max(x,y) returns the maximum of x and y, min(x,y) returns the minimum of x and y. The value printed by this program is _______. asked Aug 29, 2020
reshown Sep 10, 2020

+1 vote

Little bit tricky question,

`max(bar(p+1,n-1),p + p);`

`This function will always calculate (something very less, 17)`

`Why something very less as `

`bar(p+1,n-1) is basically min(foo(5,3),-4) `

`now no matter what foo(5,3) choses, it will never matter as foo at best calculate max, but we need min(something max, -4)`

`it will be -4`

and max(less, 17) will always be 17 no matter what

THanks answered Sep 26, 2020 by (11,240 points)
selected Sep 26, 2020