ITPEC FE Subject B October 2025 Question 12

Source exam: ITPEC FE Subject B October 2025Topic: String Processing

ITPEC FE Subject B October 2025 — Question 12 of 20

The function slides a window of length seqlen across str. For each starting position i, it compares characters one by one using index j from 1 to seqlen.

  • Blank A — `str[i + j - 1]`: Since both arrays are 1-indexed and j starts at 1, the corresponding position in str is i + j - 1. At i=1, j=1 this gives str[1], correctly aligning the first character.
  • Blank B — `j = seqlen + 1`: The while loop runs while j ≤ seqlen. If all characters match, j increments past seqlen to seqlen + 1, and the loop exits naturally. If a mismatch occurs, exit while fires with j ≤ seqlen. So j = seqlen + 1 is the success condition.

Why not others:
- str[i + j] (options a–c) — off by one; skips the first character at each window position

- j = seqlen (options a, d) — j equals seqlen during the last comparison before incrementing, so this is true even mid-comparison, not a reliable success signal

- j = seqlen - 1 (options c, f) — too early; would trigger before all characters are compared

Key rule: In 1-indexed pseudocode, when iterating j from 1 inside a window starting at i, the mapped index is i + j - 1. A while loop's natural exit means the loop variable exceeded the bound — check for bound + 1, not bound.

AI-generated — may contain errors

The original exam layout is preserved in the image so diagrams, formulas, tables, and code remain accurate.

This question comes from an official ITPEC past paper. ITPEC Practice is an independent study tool and is not affiliated with ITPEC. See the official FE past-paper collection or Report an issue.