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:
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
- LRU Cache with TTL ExpirationONSITE INTERVIEW · Seen May 2026
- Maximum Candies with At Most Two Types in a LineONSITE INTERVIEW · Seen May 2026
- Top-K KOLs by Total LikesONSITE INTERVIEW · Seen May 2026
- Compute Walking DistanceSeen Mar 2026
- Count Sawtooth SubarraysSeen Mar 2026
- Format TextSeen Mar 2026
- Memory AllocatorSeen Mar 2026
- TikTok Shopping SpreeSeen Mar 2025
public int distinctUsernames(String username) {
// write your code here
}
username"ccc"
expected3
sign in to submit