Skip to main contentSkip to solution

Sequence the given process for checking whether a string is a palindrome or not, using a deque:

(A) Load the string into the deque.

(B) Continuously remove characters from both ends.

(C) Compare the characters.

(D) Determine if the string is a palindrome based on the comparisons.

Solution

✅ Correct Option: 2

(A) Load the string into the deque, one character per position.

(B) Remove one character from the front and one from the back.

(C) Compare the two removed characters.

(D) If every pair matched until the deque has 0 or 1 characters left, the string is a palindrome. A single mismatch means it is not.

Steps (B) and (C) repeat as a loop, and the decision in (D) comes only after the comparisons are done.

Keyboard Shortcuts

  • Left arrow: Previous question
  • Right arrow: Next question
  • S key: Jump to solution
  • Q key: Jump to question