GATE Assistant

Past questions › Computer Science and Information Technology › GATE 2026 set2

GATE 2026 set2 · CS · NAT · 2 marks · Programming and Data Structures › Recursion

GATE 2026 set2 Computer Science and Information Technology question: Consider the following ANSI-C function. code The maximum possible value that can be…

Consider the following ANSI-C function.

int func(int start, int end){
  int length=end+1-start;
  if((length<1)||(start<0)||(end<0)){ return(0); }
  if(length%3==0){
    return(func(start+1, end));
  } else if(length%3==1){
    return(1+func(start, end-1));
  } else {
    return(func(start+2, end));
  }
}

The maximum possible value that can be returned from this function is ____________. (answer in integer)

Note: Ignore syntax errors (if any) in the function.

Show answer

This question is in an all-India live mock that is open now. Its answer appears here when the mock closes.

Practise this question with exam-style marking