How would you check if a string is a palindrome or not, using queues and deques.
/*If you any query do comment in the comment section else like the solution*/
Using Queues: Traverse the string character by character in forward direction and put each character in the queue. Now while queue is not empty compare the front of the queue with the string in backword direction if an unequal character is found return false immediately else if queue becomes empty then return true.
Using DeQueues: Traverse the string character by character in forward direction and put each character in the dequeue. Now while dequeue is not empty compare the front of dequeue with rear of the queue if both of them are equal then continue else return false. If dequeue becomes empty then return true.
Get Answers For Free
Most questions answered within 1 hours.