Question 10091 –
February 13, 2024Question 10096 –
February 13, 2024Question 10092 –
An array A contains n≥1 positive integers in the locations A[1], A[2],… A[n]. The following program fragment prints the length of a shortest sequence of consecutive elements of A, A[i], A[i+1],…A[j] such that the sum of their values is ≥M, a given positive number. It prints ‘n+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.
1. begin 2. i: +1; j:=1; 3. Sum := ▭; 4. min: n; finish:=false; 5. While not finish do 6. If ▭ then 7. if j=n then finish:=true. 8. else 9. begin 10. j:=j+1; 11. sum:=▭ 12. end 13. else 14. begin 15. If(j-1) < min then min:=j-1; 16. sum:=sum - A[i]; 17. i:=i+1; 18. end 19. writeln (min+1); 20. end.
Correct Answer: A
Theory Explanation.