[Java] Segment tree
\nclass Solution {\n    int A[];int B[];\n    public boolean isTransformable(String s, String t) {\n        if(s.length()!=t.length())return false;\n        if(
```\nclass Solution {\n    int A[];int B[];\n    public boolean isTransformable(String s, String t) {\n        if(s.length()!=t.length())return false;\n        if(s.equals(t))return true;\n        int A[]=new int[s.length()];\n        int B[]=new int[t.length()];\n        \n        for(int i=0;i<s.length();i++){\n            A[i]=s.charAt(i)-\'a\';\n            B[i]=t.charAt(i)-\'a\';\n        }\n        \n        \n\t\tthis.A=A;\n\t\tSeg root=new Seg(0,A.length-1);\n\t\tMap<Integer,Queue<Integer>>map=new HashMap<>();\n\t\tfor(int i=0;i<A.length;i++){\n\t\t\tif(!map.containsKey(A[i]))map.put(A[i],new LinkedList<>());\n\t\t\tmap.get(A[i]).add(i);\n\t\t}\n        \n\t\tfor(int i=0;i<B.length;i++){\n\t\t\tif(!map.containsKey(B[i])||map.get(B[i]).size()==0){\n\t\t\t\treturn false;\n\t\t\t}\n\t\t\tint index=map.get(B[i]).poll();\n\t\t\tint min=Integer.MAX_VALUE;\n\t\t\tif(index>0)min=root.query(0,index-1);\n\t\t\tif(min<B[i]){//someone less than it\n\t\t\t\treturn false;\n\t\t\t}else{\n\t\t\t\tA[index]=Integer.MAX_VALUE;\n\t\t\t\troot.update(index);\n\t\t\t}\n\t\t}\n\t\treturn true;\n    }\n    \n    class Seg{\n        int l,r;\n        int min=Integer.MAX_VALUE;\n        Seg left=null,right=null;\n        public Seg(int l,int r){\n            this.l=l;\n            this.r=r;\n            if(l!=r){\n                int mid=l+(r-l)/2;\n                if(l<=mid)left=new Seg(l,mid);\n                if(r>=mid+1)right=new Seg(mid+1,r);\n                if(left!=null)min=Math.min(left.min,min);\n                if(right!=null)min=Math.min(right.min,min);\n            }else{\n                min=A[l];\n            }\n        }\n        public int query(int s,int e){\n            if(l==s&&r==e){\n                return min;\n            }\n            int mid=l+(r-l)/2; //left :  to mid-1,\n            if(e<=mid){\n                return left.query(s,e);\n            }\n            else if(s>=mid+1){\n                return right.query(s,e);\n            }else{\n                return Math.min(left.query(s,mid),right.query(mid+1,e));\n            }\n        }\n\n        public void update(int index){\n            if(l==r){\n                min=A[l];\n                return;\n            }\n            int mid=l+(r-l)/2;\n            if(index<=mid){\n                left.update(index);\n            }else{\n                right.update(index);\n            }\n            this.min=Math.min(left.min,right.min);\n        }\n    }\n    \n}\n```
[]