Skip to main content

Posts

Showing posts with the label Day 18: Queues and Stacks Hackerrank Solution Java

Day 18: Queues and Stacks Hackerrank Solution Java

 Day 18: Queues and Stacks Hackerrank Solution Java For Explanation Check Video: Sample Input racecar Sample Output The word, racecar, is a palindrome. Code: import  java.io.*; import  java.util.*; public   class  Solution {      // Write your code here.//racecar     Stack<Character> st =  new  Stack<>();     Queue<Character> q =  new  LinkedList<>();      void  pushCharacter( char  ch){         st.push(ch); //race     }      void  enqueueCharacter( char  ch){         q.add(ch); //ecar     }      char  popCharacter(){          return  st.pop(); //c     }      char  dequeueCharacter(){          return  q.remove(); //c     }      public   static   void  main(String[] args) {         Scanner scan =  new  Scanner(System.in);         String input = scan.nextLine();         scan.close();          // Convert input String to an array of characters:          char [] s = input.toCharArray();          // Create a Solution object:         Solution p =  new  Solution();