We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
  • Hackerrank Home
  • Prepare
    NEW
  • Certify
  • Compete
  • Career Fair
  • Hiring developers?
  1. Prepare
  2. Tutorials
  3. 30 Days of Code
  4. Day 18: Queues and Stacks
  5. Discussions

Day 18: Queues and Stacks

Problem
Submissions
Leaderboard
Discussions
Editorial
Tutorial

Sort 618 Discussions, By:

votes

Please Login in order to post a comment

  • ckolos
    6 years ago+ 25 comments

    pretty simple in python3:

      class Solution:
          def __init__(self):
              self.mystack = list()
              self.myqueue = list()
              return(None)
    
          def pushCharacter(self, char):
              self.mystack.append(char)
    
          def popCharacter(self):
              return(self.mystack.pop(-1))
    
          def enqueueCharacter(self, char):
              self.myqueue.append(char)
    
          def dequeueCharacter(self):
              return(self.myqueue.pop(0))
    
    77|
    Permalink
    View more Comments..
  • tuyendev
    6 years ago+ 14 comments

    Here is my solution :

    Stack<Character> stack = new Stack<>();
    Queue<Character> queue = new LinkedList<>();
    
    void pushCharacter(Character ch) {
        stack.push(ch);
    }
    
    void enqueueCharacter(char ch) {
        queue.add(ch);
    }
    
    char popCharacter(){
        return stack.pop();
    }
    
    char dequeueCharacter() {
        return queue.remove();
    }
    
    57|
    Permalink
    View more Comments..
  • fokess
    6 years ago+ 6 comments

    My solution in c++, hope to help you

    #include <iostream>
    #include <stack>
    #include <queue>
    
    using namespace std;
    
    class Solution {
        //Write your code here
        stack<char> s;
        queue<char> q;
        public:
        void pushCharacter(char i) {
            s.push(i);
        }
        void enqueueCharacter(char i) {
            q.push(i);
        }
        char popCharacter() {
            char temp = s.top();
            s.pop();
            return temp;
        }
        char dequeueCharacter() {
            char temp = q.front();
            q.pop();
            return temp;
        }
    };
    
    38|
    Permalink
    View more Comments..
  • RodneyShag
    5 years ago+ 3 comments

    Java solution - passes 100% of test cases

    From my HackerRank solutions.

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

    Let me know if you have any questions.

    22|
    Permalink
  • MoonCWang
    4 years ago+ 0 comments

    Python 3

    class Solution:
        def __init__(self):
            self.stack, self.queue = [], []
        def pushCharacter(self,a):
            self.stack.append(a)
        def popCharacter(self):
            return self.stack.pop()
        def enqueueCharacter(self,a):
            self.queue.append(a)
        def dequeueCharacter(self):
            return self.queue.pop(0)
    
    14|
    Permalink
Load more conversations

Need Help?


View tutorial
View editorial
View top submissions
  • Blog
  • Scoring
  • Environment
  • FAQ
  • About Us
  • Support
  • Careers
  • Terms Of Service
  • Privacy Policy
  • Request a Feature