Problem ยท String

How Many Sentences? ๐ŸŒฟ

Learn this problem
โ— MediumZscalerINTERNOA

Problem statement

Given an array of words and an array of sentences, calculate how many sentences can be created by replacing any word with one of its anagrams.

Function

countSentences(wordSet: String[], sentences: String[]) โ†’ int[]

Complete the function countSentences in the editor.

countSentences has the following parameters:

  • string wordSet[n]: an array of strings
  • string sentences[m]: an array of strings
  • Returns

    int[n]: an array of m integers that denote the number of sentences that can be formed from each sentence

    Examples

    Example 1

    wordSet = ["listen", "silent", "it", "is"]sentences = ["listen it is silent"]return = [4]
    Determine that listen is an anagram of silent. Those two words can be replaced with their anagrams. The four sentences that can be created are:
  • listen it is silent
  • listen it is listen
  • silent it is silent
  • silent it is listen
  • Therefore, the output is an array with one element: [4].

    Constraints

  • 0 < n โ‰ค 10^5
  • 1 โ‰ค length of each word โ‰ค 20
  • 1 โ‰ค m โ‰ค 1000
  • 3 โ‰ค words in a sentence โ‰ค 20
  • More Zscaler problems

    drafts saved locally
    public int[] countSentences(String[] wordSet, String[] sentences) {
        // write your code here
    }
    
    wordSet["listen", "silent", "it", "is"]
    sentences["listen it is silent"]
    expected[4]
    checking account