All Anagrams

Learn how to determine if multiple strings are all anagrams of each other. While it seems as if this would require a fairly poor time and space complexity, we can come up with clever solutions that make this problem tractable.

All Anagrams

Instructions

Write a function that takes in an array of strings. Return true if all strings are anagrams of one another and false if even a single string is not an anagram of the others.

Input: Array of Strings

Output: Boolean

Examples

allAnagrams(['abcd', 'bdac', 'cabd']); // true
allAnagrams(['abcd', 'bdXc', 'cabd']); // false

Hints

  • Think about what it means for two strings to be anagrams. They should all have the same characters present in the same number, perhaps in a different order.
  • It would make sense to express the time complexity in terms of two variables.

Level up your interview prep. Join Educative to access 80+ hands-on prep courses.