FastPrepGood Subsequences
Problems/Good Subsequences

Good Subsequences

Nutanix logoNutanix● HardFULLTIMEOA

Updated Sep 2026

QuestionFunctionExamplesConstraints

Problem statement

A subsequence of a given string is generated by deleting zero or more characters from a string, then concatenating the remaining characters. A good subsequence is one where the frequency of each character is the same. Given a string that consists of n Latin letters, determine how many good subsequences it contains. Since the answer can be quite large, compute its modulo (10^9 + 7).

Note: An empty subsequence is not a good subsequence.

Function

countGoodSubsequences(word: String) → int

Complete the function countGoodSubsequences in the editor below.

countGoodSubsequences has the following parameter(s):

  • string word: a string that consists of only lowercase Latin letters

Returns int: the number of good subsequences modulo (10^9 + 7)

Examples

Example 1

word = "abca"return = 12

A total of 15 non-empty subsequences can be formed from words: "a", "a", "aa", "ab", "aba", "abc", "abca", "ac", "aca", "b", "ba", "bc", "bca", "c", and "ca". The only subsequences that are not good are "aba," "aca," and "abca" as the frequency of character "a" is 2, and every other character is 1. The total number of good subsequences = 15 - 3 = 12 and answer to the above example = 12 modulo (109+7) = 12.

Example 2

word = "abcd"return = 15

All of the non-empty subsequences are good subsequences. They are "a", "ab", "abc", "abcd", "abd", "ac", "acd", "ad", "b", "bc", "bcd", "bd", "c", "cd", and "d".

Example 3

word = "aaa"return = 7

Every non-empty subsequence contains only the character a, so the character frequencies are equal. There are 2^3 - 1 = 7 such subsequences.

Constraints

  • 1 ≤ length of word ≤ 10^5
  • word[i] is in the range [a-z]

More Nutanix Online Assessment questions

  • Min Cost to Connect All PointsOA · Seen Jun 2026
  • Digit Changes for a Multiple of 9OA · Seen Aug 2025
  • Gas Station Loop StartOA · Seen Aug 2025
  • Number of Players (for MTS2)OA · Seen Oct 2024
  • Work Schedules (for MTS2)OA · Seen Oct 2024
  • Minimum Operations to Convert ArrayOA · Seen Apr 2024
  • No Adjacent CharactersOA · Seen Apr 2024
  • Build a BST From a ListOA · Seen Nov 2022
  • Delete Even-Valued Nodes From a Linked ListOA · Seen Nov 2022
  • Maximum Value of the Last RobotOA · Seen Aug 2021

Similar questions at other companies

  • Unique Digit Permutations Without Leading ZeroMicrosoft · ONSITE INTERVIEWMicrosoft interview questions
  • Even and Odd Digit Pattern ProbabilityJane Street · PHONE SCREENJane Street interview questions
  • Binary CircuitAkuna Capital · OAAkuna Capital interview questions
  • Stable Workload Redistribution TreesTower Research Capital · OA
  • Minimum Numeric Code TransformationAdobe · OAAdobe interview questions
  • Count Valid A-B-C Sequences Under a Modulo-Four RuleInfosys · OAInfosys interview questions
  • Break a PalindromeRoblox · OARoblox interview questions
  • Minimize Expression with ParenthesesPinterest · OAPinterest interview questions
  • Guess the WordGoogle · OA · PHONE SCREENGoogle interview questions
  • String Transformation (Also for Infra Automation Intern)Snowflake · OASnowflake interview questions

Nutanix interview experiences

  • Nutanix interviews · November 2026
  • Nutanix SWE Intern Phone Screens: 20 Experiences (Part 3 of 3)
  • Nutanix SWE Intern OA Questions: 16 Experiences (Part 2 of 3)
  • Nutanix U.S. SWE Intern Interviews: 54 Experiences (Part 1 of 3)
  • Nutanix SWE OA and Interviews, Level Not Reported: 9 Experiences
  • Nutanix Intern Debugging Round and Interviews: 25 Experiences
All Nutanix interview questionsSee Nutanix hiring insights
Saved
class Solution {
    public int countGoodSubsequences(String word) {
      // write your code here
    }

}
Checking account…