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.
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
(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.
Related questions:
2026: 29 May Shift 2
2026: 20 May Shift 1