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.
public static void main(String[] args) {
/* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */
Scanner s=new Scanner(System.in);
int n=s.nextInt();
s.nextLine();
Queue<Integer> q=new LinkedList<>();
while(n-->0){
String str=s.nextLine();
if(str.startsWith("1")){
int val= Integer.parseInt(str.split(" ")[1]);
q.add(val);
}
else if(str.equals("2")){
if(!q.isEmpty()) q.remove();
}
else {
if(!q.isEmpty())
System.out.println(q.peek());
}
}
}
}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Queue using Two Stacks
You are viewing a single comment's thread. Return to all comments →
java solution
import java.io.; import java.util.;
public class Solution {
}