GATEverse
← GATE CSE 1997

Q17

NATMarks unknown

An array AA contains n≥1n \geq 1 positive integers in the locations A[1],A[2],…A[n]A[1], A[2], \dots A[n]. The following program fragment prints the length of a shortest sequence of consecutive elements of AA, A[i],A[i+1],…,A[j]A[i], A[i+1], \dots,A[j] such that the sum of their values is ≥M\geq M, a given positive number. It prints ‘n+1n+1’ if no such sequence exists. Complete the program by filling in the boxes. In each case use the simplest possible expression. Write only the line number and the contents of the box. begin i:=1;j:=1; sum := ◻ min:=n; finish:=false; while not finish do if ◻ then if j=n then finish:=true else begin j:=j+1; sum:= ◻ end else begin if(j-i) < min then min:=j-i; sum:=sum –A[i]; i:=i+1; end writeln (min +1); end.

Sign in to save attempts.

Loading…