Skip to content
Programmingoneonone
Programmingoneonone

Learn everything about programming

  • Home
  • CS Subjects
    • Internet of Things (IoT)
    • Digital Communication
    • Human Values
  • Programming Tutorials
    • C Programming
    • Data structures and Algorithms
    • 100+ Java Programs
    • 100+ C Programs
  • HackerRank Solutions
    • HackerRank Algorithms Solutions
    • HackerRank C problems solutions
    • HackerRank C++ problems solutions
    • HackerRank Java problems solutions
    • HackerRank Python problems solutions
Programmingoneonone
Programmingoneonone

Learn everything about programming

HackerRank Day 18 Queues and Stacks 30 days of code solution

YASH PAL, 31 July 202413 October 2025

HackerRank Day 18 Queues and Stacks solution – In this HackerRank Day 18 Queues and Stacks 30 days of the code problem statement, we need to check whether a given string is a palindrome number or not. rest of the things already defined.

Welcome to Day 18! Today we’re learning about Stacks and Queues. A palindrome is a word, phrase, number, or other sequence of characters which reads the same backwards and forwards. Can you determine if a given string, S, is a palindrome?

To solve this challenge, we must first take each character in S, enqueue it in a queue, and also push that same character onto a stack. Once that’s done, we must dequeue the first character from the queue and pop the top character off the stack, then compare the two characters to see if they are the same; as long as the characters match, we continue dequeueing, popping, and comparing each character until our containers are empty (a non-match means S isn’t a palindrome).

Write the following declarations and implementations:

Two instance variables: one for your stack, and one for your queue.
A void pushCharacter(char ch) method that pushes a character onto a stack.
A void enqueueCharacter(char ch) method that enqueues a character in the queue instance variable.
A char popCharacter() method that pops and returns the character at the top of the stack instance variable.
A char dequeueCharacter() method that dequeues and returns the first character in the queue instance variable.

Input Format
You do not need to read anything from stdin. The locked stub code in your editor reads a single line containing string s. It then calls the methods specified above to pass each character to your instance variables.

Constraints
S is composed of lowercase English letters.

Output Format
You are not responsible for printing any output to stdout.
If your code is correctly written and s is a palindrome, the locked stub code will print The word, s, is a palindrome.; otherwise, it will print The word, s, is not a palindrome.

Problem solution in Python 2 programming.

class Solution:
    # Write your code here
    stack = []
    queue = []
    
    def __init(self):
        self.stack = []
        self.queue = []
        
    def pushCharacter(self, ch):
        self.stack.insert(0, ch)
        
    def popCharacter(self):
        return self.stack.pop(0)
    
    def enqueueCharacter(self, ch):
        self.queue.append(ch)
        
    def dequeueCharacter(self):
        return self.queue.pop(0)

Problem solution in Python 3 programming.

class Solution:

    def __init__(self):
        self.stack = []
        self.queue = []
    
    def pushCharacter(self, ch):
        self.stack.append(ch)
    
    def enqueueCharacter(self, ch):
        self.queue.append(ch)
    
    def popCharacter(self):
        return self.stack.pop()
    
    def dequeueCharacter(self):
        return self.queue.pop(0)

Problem solution in java programming.

public class Solution {
    LinkedList<Character> queue = new LinkedList();
    LinkedList<Character> stack = new LinkedList();
    
    public void pushCharacter(char ch){
        stack.push(ch);
    }
    
    public void enqueueCharacter(char ch){
        queue.add(ch);
    }
    
    public char popCharacter(){
        return stack.pop();
    }
    
    public char dequeueCharacter(){
        return queue.remove();
    }

Problem solution in c++ programming.

#include <iostream>
#include <stack>
#include <queue> 

using namespace std;

class Solution {
    //Write your code here
    std::stack<char> mystack;
    std::queue<char> myqueue;
    
    public:
        void pushCharacter(char ch){
            mystack.push(ch);
        }
    
        void enqueueCharacter(char ch){
            myqueue.push(ch);
        }
    
        char popCharacter(){
            char top = mystack.top();
            mystack.pop();
            return top;
        }
    
        char dequeueCharacter(){
            char front = myqueue.front();
            myqueue.pop();
            return front;
        }
};

Problem solution in Javascript programming.

function Solution(){
  this.stack = [];
  this.queue = [];
}

Solution.prototype.pushCharacter = function pushCharacter (char) {
  this.stack.push(char);
};

Solution.prototype.enqueueCharacter = function enqueueCharacter (char) {
  this.queue.push(char);
};

Solution.prototype.popCharacter = function popCharacter () {
  return this.stack.pop();
};

Solution.prototype.dequeueCharacter  = function dequeueCharacter () {
  return this.queue.shift();
};

30 days of code coding problems solutions HackerRank

Post navigation

Previous post
Next post

Pages

  • About US
  • Contact US
  • Privacy Policy

Follow US

  • YouTube
  • LinkedIn
  • Facebook
  • Pinterest
  • Instagram
©2025 Programmingoneonone | WordPress Theme by SuperbThemes