Are All Words Anagrams?
Updated
Problem statement
For each of the 26 lowercase letters, count how often it appears in a word. Two words are anagrams when all 26 counts agree. For example, "note" and "tone" are anagrams (one each of e, n, o, t), while "too" and "to" are not (two os against one).
You are given a list words. Return true if every pair of words in the list are anagrams of each other. Otherwise return false.
- Repeats are allowed: a word and an exact copy of it have the same counts, so the pair passes.
- A list with one word gives
true.
Function
allAnagrams(words: String[]) → booleanExamples
Example 1
words = ["stale","least","slate","tales"]return = trueEvery word uses the letters a, e, l, s, t once each. So any word can be rearranged into any other, and the answer is true.
Example 2
words = ["races","cares","scare","acres","crate"]return = falseThe first four words each use the letters a, c, e, r, s once. "crate" has a t where the others have an s. So not every pair is an anagram, and the answer is false.
Example 3
words = ["deed","dede","dded"]return = falseAll three words have 4 letters and use only d and e. "deed" and "dede" each have two ds and two es, but "dded" has three ds and one e. The counts differ, so the answer is false.
Constraints
1 <= words.length <= 10001 <= words[i].length <= 50- Every
words[i]contains only lowercase English letters.
More DocuSign Online Assessment questions
- Max Sum With No Two Adjacent PicksOA · Seen Apr 2026
- Max Sum With No Two Adjacent Picks on a CircleOA · Seen Apr 2026
- Beautiful Number OrderingsOA · Seen Feb 2026
- Grid Path With the Most ClearanceOA · Seen May 2025
- Vehicle Mixes for a Wheel TotalOA · Seen May 2025
- Count Sales Rung Up at the Wrong PriceOA · Seen Feb 2021
- Most Disjoint Intervals From Starts and DurationsOA · Seen Feb 2021
- Fewest Fountains to Water the GardenOA · Seen Feb 2021
- Lowest Start That Keeps Running Totals PositiveOA · Seen Feb 2021
- Fewest Student Groups Within a Level GapOA · Seen Nov 2020
Similar questions at other companies
- Count User Mentions in Chat MessagesRamp · OARamp interview questions
- Blood Type Inheritance: Possible Parent GenotypesAbridge · OAAbridge interview questions
- Count Repeated Request IDs (Data Science OA)McKinsey & Company · OAMcKinsey & Company interview questions
- Flat JSON Value DifferencesChubb · OAChubb interview questions
- Get Search ResultsJP Morgan Chase · OAJP Morgan Chase interview questions
- Lexicographic Word FrequenciesUpstart · OAUpstart interview questions
- Email Log Processing, Grouping, and SortingStripe · OAStripe interview questions
- Most Frequent CharacterMicrosoft · OAMicrosoft interview questions
- Get Maximum Information GainAmazon · OA
- Better CompressionGoldman Sachs · OAGoldman Sachs interview questions