@@ -0,0 +1,2012 @@
+/*%0A * Copyright 2017 haeun kim%0A *%0A * Licensed under the Apache License, Version 2.0 (the %22License%22);%0A * you may not use this file except in compliance with the License.%0A * You may obtain a copy of the License at%0A *%0A *      http://www.apache.org/licenses/LICENSE-2.0%0A *%0A * Unless required by applicable law or agreed to in writing, software%0A * distributed under the License is distributed on an %22AS IS%22 BASIS,%0A * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.%0A * See the License for the specific language governing permissions and%0A * limitations under the License.%0A */%0A%0Apackage algorithm.hackerrank.Stack;%0A%0Aimport java.io.*;%0A%0A/**%0A * Created by haeun on 2017-10-05%0A * Site       : https://www.hackerrank.com/challenges/maximum-element%0A * Difficulty : Easy%0A */%0Apublic class MaximumElement%7B%0A    String%5B%5D items = new String%5B100000%5D;%0A    int%5B%5D maximum = new int%5B100000%5D;%0A    int top = -1;%0A%0A    public void push(String item) %7B%0A        items%5B++top%5D = item;%0A        if(top%3E0)%7B%0A            maximum%5Btop%5D = (maximum%5Btop-1%5D %3E Integer.parseInt(item))?maximum%5Btop-1%5D:Integer.parseInt(item);%0A        %7Delse %7B%0A            maximum%5Btop%5D= Integer.parseInt(item);%0A        %7D%0A    %7D%0A%0A    public String pop() %7B%0A        if (top==-1)%7B%0A            return null;%0A        %7D%0A        return items%5Btop--%5D;%0A    %7D%0A%0A    public String peek() %7B%0A        if(top==-1)%7B%0A            return null;%0A        %7D%0A        return %22%22+maximum%5Btop%5D;%0A    %7D%0A%0A    public static void main(String%5B%5D args) throws IOException%7B%0A        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));%0A        int n = Integer.parseInt(br.readLine());%0A        MaximumElement me = new MaximumElement();%0A        for(int i=0; i%3Cn; i++)%7B%0A            String%5B%5D input = br.readLine().split(%22 %22);%0A            if(input%5B0%5D.trim().equals(%221%22))%7B%0A                me.push(input%5B1%5D);%0A            %7Delse if(input%5B0%5D.trim().equals(%222%22))%7B%0A                me.pop();%0A            %7Delse%7B%0A                System.out.println(me.peek());%0A            %7D%0A        %7D%0A    %7D%0A%7D%0A

Solve MaximumElement from Hackerrank