• + 3 comments

    It works fine, but I'm getting timeout in tests 8, 9, 10

     public static void main(String[] args) {
            Scanner s = new Scanner(System.in);
    
            Stack<String> history = new Stack<>();
            StringBuilder current = new StringBuilder();
    
            int count = s.nextInt();
            for (int i = 0; i < count; i++) {
                int operation = s.nextInt();
                switch (operation) {
                    case 1:
                        history.push(current.toString());
                        current.append(s.next());
                        break;
                    case 2:
                        history.push(current.toString());
                        current = new StringBuilder(current.substring(0, current.length() - s.nextInt()));
                        break;
                    case 3:
                        System.out.println(current.charAt(s.nextInt() - 1));
                        break;
                    case 4:
                        current = new StringBuilder(history.pop());
                        break;
                }
            }
        }
    

    How can I make it better?