Skip to main contentSkip to solution

Arrange the following steps of checking whether a string is palindrome or not, using the deque in correct order:

A. Insert all characters of the string in deque using the INSERTREAR function one after the other.

B. Remove one character from the front and one character from the rear end of the deque using DELETERFRONT and DELETEREAR functions.

C. Match these two removed characters.

D. If these characters are same, then repeat this process of removing two characters, one from front and another from rear and comparing them until these two characters do not match. If all characters match, then stop with success, else stop with fail.

Solution

✅ Correct Option: 1

The string must first be loaded into the deque (A). Then one character is removed from each end (B), the two removed characters are compared (C), and the process is repeated while they match, ending in success or failure (D).

A. Insert all characters at the rear one after another.

B. Delete one character from the front and one from the rear.

C. Compare the two removed characters.

D. If they match, repeat B and C until a mismatch occurs or all characters are matched.


Option 2: D (repeat the process) cannot come before C, because the repeat decision depends on the comparison result.

Options 3 and 4: removal or comparison cannot happen before the characters are inserted into the deque.

Keyboard Shortcuts

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