FastPrepHow Many Sentences? 🌿
Problems/How Many Sentences? 🌿

How Many Sentences? 🌿

Zscaler logoZscaler● MediumINTERNOA

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

You are given an array of words wordSet and an array of sentences sentences. Two words are anagrams of each other when they use the same letters in a different order.

For each sentence, count how many different sentences you can make by replacing any of its words with one of its anagrams from wordSet. A word may also stay as it is.

For example, with wordSet = ["listen", "silent", "it", "is"] and the sentence "listen it is silent", the words "listen" and "silent" are anagrams of each other. Each of them can be written two ways, and "it" and "is" have one way each. So you can make 2 × 2 = 4 sentences.

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[m]: 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]

listen and silent are anagrams of each other, so each of them can be replaced by the other. it and is have no other anagram in wordSet. The four sentences that can be created are:

  • listen it is silent
  • listen it is listen
  • silent it is silent
  • silent it is listen

So the output is an array with one element: [4].

Constraints

  • 0 < n ≤ 105, where n is the length of wordSet
  • 1 ≤ length of each word ≤ 20
  • 1 ≤ m ≤ 1000, where m is the length of sentences
  • 3 ≤ words in a sentence ≤ 20
  • Every word is made of lowercase English letters, and the words of wordSet are all different.
  • A sentence is its words separated by single spaces, and every word of a sentence is in wordSet.
  • Each answer is at most 231 − 1.

More Zscaler interview questions

  • Rate Limiter with Hourly and Daily Effort QuotasPHONE SCREEN · Seen Jul 2026
  • Asteroid CollisionONSITE INTERVIEW · Seen Sep 2024
  • Check Whether a Byte Is NonzeroONSITE INTERVIEW · Seen Sep 2024
  • Count Vowel PermutationsONSITE INTERVIEW · Seen Sep 2024
  • Merging PalindromesPHONE SCREEN · Seen Sep 2024
  • Find the Element With Odd FrequencyPHONE SCREEN · Seen Jun 2024
  • Longest Common Subsequence LengthONSITE INTERVIEW · Seen Jun 2024
  • Merge IntervalsPHONE SCREEN · Seen Jun 2024
  • Run-Length EncodingONSITE INTERVIEW · Seen Jun 2024
  • Sum of Divisors of the Array GCDPHONE SCREEN · Seen Jun 2024

Similar questions at other companies

  • Classify Password StrengthHackerRank · OA · PHONE SCREEN · ONSITE INTERVIEWHackerRank interview questions
  • Count One-Swap Number PairsCapital One · OACapital One interview questions
  • Perfect SubstringAXQ Capital · OA
  • Count Suffix Word PairsTikTok · OATikTok interview questions
  • Password Clues and the Next CommandOpenAI · OAOpenAI interview questions
  • Decode Words with Anagram KeysCresta · OACresta interview questions
  • Parcel Event TrackingAirbnb · OAAirbnb interview questions
  • Maximum Valid Substring FrequencyMicrosoft · OAMicrosoft interview questions
  • Longest Distinct StringSuperhuman · OASuperhuman interview questions
  • Longest String ChainVisa · OAVisa interview questions

Zscaler interview experiences

  • Zscaler Campus Drive Interviews: 4 Experiences (Part 6 of 6)
  • Zscaler Java, QA and Cloud Rounds: 8 Experiences (Part 5 of 6)
  • Zscaler UI and DevTest Rounds: 8 Experiences (Part 4 of 6)
  • Zscaler Intern, QA and SRE Rounds: 7 Experiences (Part 3 of 6)
  • Zscaler SDE C++ and OS Rounds: 7 Experiences (Part 2 of 6)
  • Zscaler Campus SDE Interviews: 37 Experiences (Part 1 of 6)
All Zscaler interview questionsSee Zscaler hiring insights
Saved
class Solution {
    public int[] countSentences(String[] wordSet, String[] sentences) {
        // write your code here
    }

}
Checking account…