Problem · String

Changing Username

MediumTiktokOA
See Tiktok hiring insights

A TikTok user has a username represented by a string of lowercase English letters, username. The user wants to transform their username to explore possible variations. The user can perform the following operations on the username multiple times, in any order:

  • Replace an occurrence of 'cc' with 'a'.
  • Replace an occurrence of 'dd' with 'b'.
  • The user may also choose not to apply any operations, leaving the username unchanged.

    Given the string username, determine the total number of distinct usernames that can be generated by applying these transformations. Since the result can be large, return the total count modulo 109+7.

    Examples
    01 · Example 1
    username = "ccc"
    return = 3
    The possible usernames that can be generated are:
  • "ccc" → "ac"
  • "ccc" → "ca"
  • "ccc" (No operation is applied)
  • Hence the answer is 3.
    More Tiktok problems
    drafts saved locally
    public int distinctUsernames(String username) {
      // write your code here
    }
    
    username"ccc"
    expected3
    checking account