Changing Username
Updated
Problem statement
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.
Function
distinctUsernames(username: String) → intExamples
Example 1
username = "ccc"return = 3The possible usernames that can be generated are:
- "ccc" → "ac"
- "ccc" → "ca"
- "ccc" (No operation is applied)
Hence the answer is 3.
More TikTok interview questions
- Center of the Largest Perfect X-ShapeOA · Seen Nov 2026
- Count Subarrays Matching a Comparison PatternOA · Seen Nov 2026
- Count Suffix Word PairsOA · Seen Nov 2026
- Minimum Cost of Every K-Capable Model SetOA · Seen Nov 2026
- Longest Substring Without Repeating CharactersPHONE SCREEN · Seen Oct 2026
- Next Greater Indices and Maximum GapPHONE SCREEN · Seen Oct 2026
- Count Subarrays with at Least K Equal-Fruit PairsOA · Seen Oct 2026
- Shell Command Counts with History ReferencesOA · Seen Oct 2026
- Product Minus Sum of DigitsOA · Seen Aug 2026
- Count 2x2 Submatrices by Black CellsOA · Seen Aug 2026
Similar questions at other companies
- Longest Palindromic SubsequenceAXQ Capital · OA
- Maximum Equal-Bit Pairs in a SubsequenceAmazon · OA
- Longest Subsequence That Is a SubstringBooking.com · OA
- Count Digit Replacements with No Equal Adjacent DigitsMicrosoft · OAMicrosoft interview questions
- Palindrome CounterGoldman Sachs · OAGoldman Sachs interview questions
- Longest String ChainVisa · OAVisa interview questions
- Minimum-Cost Digit String DecodingSquadStack.ai · OA
- Maximum Redundancy After One Segment FlipBloomberg LP · OABloomberg LP interview questions
- Substrings Without a Target SubsequencePhonePe · OAPhonePe interview questions
- Minimum Edit-Distance String for Each QueryTarget · OA
TikTok interview experiences
- TikTok AI Infra Intern LLM Round 2: 1 Experience
- TikTok AI Infra Intern DeepSpeed Round: 1 Experience
- TikTok AI Infra Intern Kernel Round: 1 Experience
- TikTok AI Infra Intern Interviews, 3 Rounds: 1 Experience
- TikTok AI Infra Intern Interview Timeline: 1 Experience
- TikTok AI Infra Intern Onsite Round 2: 1 Experience