title: How to sort an array of strings with anagrams next to each other
body: <p>How to sort an array of strings with anagrams next to each other?  </p>
  
  <p>Eg:</p>
  
  <p>input {god, dog, abc, cab, man}<br>
  output {abc, cab, dog, god, man}</p>
  
  <p>My approach:
  Sort the array ( without considering the anagrams case) in O(nlogn). Next,
  pick up the first string &amp; create a histogram for the string, and compare the histogram with the remaining strings histograms in the array and place the matching strings at appropriate position of the array ..repeat until it reaches array size.. this algo takes worst case of O(n^3) (if we assume that in worst case, each string is also of size n) &amp; extra space for the histogram representation</p>
  
  <p>Histogram approach taken from the ref:
  <a href="https://stackoverflow.com/questions/4236906/finding-if-two-words-are-anagrams-of-each-other">finding if two words are anagrams of each other</a></p>
  
  <p>Can we do better than this?</p>