FastPrepFastPrep
Problem Brief

Changing Username

OA
See Tiktok online assessment and 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.

    1Example 1

    Input
    username = "ccc"
    Output
    3
    Explanation
    The possible usernames that can be generated are:
  • "ccc" → "ac"
  • "ccc" → "ca"
  • "ccc" (No operation is applied)
  • Hence the answer is 3.
    public int distinctUsernames(String username) {
      // write your code here
    }
    
    Input

    username

    "ccc"

    Output

    3

    Sign in to submit your solution.