class LexSort { static void solve(String s,String out, ArrayList<String> ans ,int i){ if(i==s.length()){ ans.add(out); return; } char ch=s.charAt(i); solve(s,out,ans,i+1); solve(s,out+String.valueOf(ch),ans,i+1); } //Function to return the lexicographically sorted power-set of the string. static ArrayList<String> powerSet(String s) { ArrayList<String> ans= new ArrayList<>(); solve(s,"",ans,0); return ans; } }
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter