Optimized version where base is only converted to char list and sorted once.