FastPrepCount Sentences From Anagram Swaps
Problems/Count Sentences From Anagram Swaps

Count Sentences From Anagram Swaps

Adobe logoAdobe● MediumFULLTIMEPHONE SCREEN
QuestionFunctionExamplesConstraints

Problem statement

Source note: The judged answer here is a product per sentence: for each of its words, the number of listed words made of exactly the same letters. An Adobe MTS-2 report gives this task for the first round with its function name and two small examples, but no limits and no rule for a sentence word that is missing from the list.

Our choices: the listed words are all different and every sentence word is listed, at most 1000 words of up to 20 letters, 100 sentences of up to 10 words, every answer at most 10^9, and new examples (the report's examples are not reused).

The judged task matches the report at about 95%.

Two words are anagrams when one can be made by rearranging all the letters of the other (a word is an anagram of itself).

You are given a list of different words words and a list of sentences. From a sentence you can make new sentences by replacing each of its words, independently, with any word from words that is an anagram of it (or keeping it).

For each sentence, return how many different sentences can be made this way, counting the sentence itself.

Function

countSentences(words: String[], sentences: String[]) → int[]

Examples

Example 1

words = ["stop","pots","tops","a","net","ten"]sentences = ["stop a net","a a"]return = [6,1]

In "stop a net", stop can be any of 3 words (stop, pots, tops), a only itself, and net 2 (net, ten): 3 × 1 × 2 = 6. In "a a" each word has 1 choice: 1.

Example 2

words = ["dusty","study","night","thing"]sentences = ["night study night"]return = [8]

Each of the three words has 2 choices, chosen independently: 2 × 2 × 2 = 8.

Example 3

words = ["one"]sentences = ["one"]return = [1]

One word with no other anagram: 1 sentence (itself).

Constraints

  • 1 <= words.length <= 1000, the words are all different, and each has 1 to 20 lowercase English letters.
  • 1 <= sentences.length <= 100
  • Each sentence is 1 to 10 words separated by single spaces, and every word of every sentence appears in words.
  • Every answer is at most 10^9.

More Adobe problems

  • Evaluate a Parenthesized Integer ExpressionPHONE SCREEN · Seen Oct 2026
  • All Elements of Two BSTs in OrderPHONE SCREEN · Seen Aug 2026
  • Rotate an Array In PlaceOA · PHONE SCREEN · Seen Aug 2026
All Adobe interview questionsSee Adobe hiring insights
Saved
public int[] countSentences(String[] words, String[] sentences) {
    // Write your code here.
}
Checking account…