import java.util.*;
import java.lang.*;
import java.io.*;

// The main method must be in a class named "Main".
import java.util.Stack;

class MinStack {
    private Stack<Integer> stack;
    private Stack<Integer> minStack;

    /** initialize your data structure here. */
    public MinStack() {
        stack = new Stack<>();
        minStack = new Stack<>();
    }

    public void push(int x) {
        stack.push(x);
        if (minStack.isEmpty() || x <= minStack.peek()) {
            minStack.push(x);
        }
    }

    public void pop() {
        if (stack.isEmpty()) return;
        int popped = stack.pop();
        if (popped == minStack.peek()) {
            minStack.pop();
        }
    }

    public int top() {
        if (stack.isEmpty()) return -1; // or throw an exception
        return stack.peek();
    }

    public int getMin() {
        if (minStack.isEmpty()) return -1; // or throw an exception
        return minStack.peek();
    }
}


class Main {
    public static void main(String[] args) {
        System.out.println("Hello world!");
    }
}

Embed on website

To embed this program on your website, copy the following code and paste it into your website's HTML: