Ad
  • Default User Avatar

    This is true but it is not the only reason it is not optimal. As the comment above yours said, sorting takes klog k time (where k is the length of a word) which means that the total runtime will be n*klogk. Using a dictionary, for example, will only take nk time.