FastPrepHow Many Sentences?

How Many Sentences?

Chubb logoChubb● MediumINTERNOA
Learn

Problem statement

Words are anagrams when their characters can be rearranged to match. For each sentence, replace every word independently with any anagram present in wordSet. Return the number of sentences that can be formed.

Function

countSentences(wordSet: String[], sentences: String[]) → long[]

Examples

Example 1

wordSet = ["listen","silent","it","is"]sentences = ["listen it is silent"]return = [4]

Each occurrence of the listen/silent anagram group has two choices, so the product is four.

Constraints

  • 1 <= wordSet.length, sentences.length <= 1000
  • Inputs contain lowercase English words separated by single spaces.
  • Each answer fits in a signed 64-bit integer.

More Chubb problems

See Chubb hiring insights
public long[] countSentences(String[] wordSet, String[] sentences) {
  // Write your code here.
}
wordSet["listen","silent","it","is"]
sentences["listen it is silent"]
expected[4]
Checking account…