ITPEC FE Subject B October 2024 Question 12

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

ITPEC FE Subject B October 2024 — Question 12 of 20

Palindrome check with two pointers — fill in the blanks for a function that checks whether a character array is a palindrome using left/right index convergence.

The function uses two pointers: left starts at 1, right starts at the array length. Each iteration compares s[left] and s[right]:

  • If they match, both pointers move inward: left ← left + 1, right ← right - 1
  • If they don't match, ok ← false and the loop breaks

Blank A must be s[left] = s[right] (equality check — matching means we continue).
Blank B must be right ← right - 1 (move the right pointer inward symmetrically).

Why not others:
- (a) right ← right + 1 moves right outward, causing an out-of-bounds access

- (c) right ← right + left produces meaningless index values

- (d) right ← right - left does not mirror the symmetric convergence pattern

- (e–h) use s[left] ≠ s[right] as condition A, which inverts the logic: matching characters would trigger ok ← false

Key rule: Two-pointer palindrome check — when characters match, move both pointers inward (left + 1, right - 1); when they don't, the string is not a palindrome.

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.