@@ -0,0 +1,2322 @@
+//https://www.hackerrank.com/challenges/simple-text-editor%0Aimport java.io.*;%0Aimport java.util.*;%0A%0Apublic class Solution %7B%0A    public static void main(String%5B%5D args) throws IOException %7B%0A        %0A        //I/O%0A        final StringBuilder sb = new StringBuilder();%0A        final BufferedReader br = new BufferedReader(new InputStreamReader(System.in));%0A        %0A        //For each query...%0A        final StringBuilder S = new StringBuilder();%0A        final Deque%3CQuery%3E stack = new ArrayDeque%3CQuery%3E();%0A        for(int Q = Integer.parseInt(br.readLine()); Q %3E 0; --Q)%7B%0A            %0A            //Get query%0A            final String%5B%5D line = br.readLine().split(%22 %22);%0A            final byte T = Byte.parseByte(line%5B0%5D);%0A            %0A            //Perform Get%0A            if(T == 3)%7B%0A                final int k = Integer.parseInt(line%5B1%5D) - 1;%0A                sb.append(S.charAt(k) + %22%5Cn%22);%0A            %0A            //Perform Undo%0A            %7D else if(T == 4)%7B%0A                stack.pop().undo().perform(S);%0A                %0A            //Perform Append / Erase%0A            %7D else %7B%0A                final Query q = (T == 1) ? %0A                    new Append(line%5B1%5D) : %0A                    new Erase(S.substring(S.length() - Integer.parseInt(line%5B1%5D)));%0A                q.perform(S);%0A                stack.push(q);%0A            %7D%0A        %7D%0A        %0A        //Print output%0A        System.out.print(sb);%0A    %7D%0A    %0A    private static abstract class Query %7B%0A        protected final String w;%0A        public Query(final String w)%7B%0A            this.w = w;%0A        %7D%0A        public abstract void perform(final StringBuilder S);%0A        public abstract Query undo();%0A    %7D%0A    %0A    private static class Append extends Query %7B%0A        public Append(final String w)%7B%0A            super(w);%0A        %7D%0A        public void perform(final StringBuilder S)%7B%0A            S.append(this.w);%0A        %7D%0A        public Erase undo()%7B%0A            return new Erase(this.w);%0A        %7D%0A    %7D%0A    %0A    private static class Erase extends Query %7B%0A        public Erase(final String w)%7B%0A            super(w);%0A        %7D%0A        public void perform(final StringBuilder S)%7B%0A            final int len = S.length();%0A            S.delete(len - this.w.length(), len);%0A        %7D%0A        public Append undo()%7B%0A            return new Append(this.w);%0A        %7D%0A    %7D%0A%7D%0A

Create simple-text-editor.java