Fresh Studio Name Swaps
Preview mode. Log in to edit, run, submit, and save progress.
Fresh Studio Name Swaps
A naming platform stores a list of unique lowercase studio names. To generate a possible new pair of studio names, choose two different existing names and swap only their first letters. The ordered choice matters: choosing name A first and name B second is considered different from choosing name B first and name A second. After swapping the first letters, both newly formed names must be absent from the original studio list. If either newly formed name already exists, that ordered choice is rejected. Count how many ordered choices create two fresh studio names. Input Format: You are given an array names containing unique lowercase strings. Output Format: Return the number of valid ordered first-letter swaps.
Examples
names = ["spark", "glow", "sail", "grain"]
8
Explanation: 8 ordered swaps create two fresh names. For example: spark + glow -> gpark, slow; spark + grain -> gpark, srain; glow + spark -> slow, gpark. Therefore the output is 8.
Approach hint
Swapping first letters only cares about each name's suffix.
Common mistake
Skipping assumptions, edge cases, or trade-offs can make an otherwise good answer feel incomplete.