Hackerrank 30 days of code Java Solution: Day 18: Queues and Stacks

Hackerrank Day 18 problem talk’s about the most important topic: data structures. Data structures is like advance tools for every programmer, which are used to solve complex problems in efficient way. It is a very vast topic and requires a detail understanding and practice to master it.

I would personally recommend the following book: Data Structures by Reema Thareja and Cormen for advance learning.
This challenge includes the two most common data structure used: Queue and Stacks


Stacks work on principle of LIFO (Last-In-First-Out), which means the last object to enter stack would be removed first.


Queue works on the principle of FIFO(First-In-First-Out),which means the the one thing to enter the scenario will leave first. For example, the reservation line for movie tickets. The first person to enter the line takes the ticket and leave.

So now lets jump to the problem statement of Day 18


Write a program to check for string is palindrome or not using stack and queue.A palindrome is a word, phrase, number, or other sequence of characters which reads the same backwards and forwards.For example “racecar” is a palindrom

Sample Input

Sample Output

Solution to the problem is :

Thanks for the visit checkout the day 19 tutorial as well.. 🙂

Leave a Reply

Your email address will not be published. Required fields are marked *