Username Change
Updated
Problem statement
You are given a list of usernames names. For each username, decide whether swapping two characters at different positions can produce a lexicographically smaller string.
For this exercise, assume each username contains lowercase English letters. One swap exchanges exactly two existing positions. Compare the new string with the original: at the first differing position, a smaller letter makes the new string smaller. It does not have to be fully sorted.
Return a Boolean array in input order. A username of length less than two cannot be improved. Swapping equal letters leaves the string unchanged, so it does not count as an improvement.
Function
canImproveUsernames(names: String[]) → boolean[]Examples
Example 1
names = ["foo","bar","rim"]return = [false,true,true]foo has no smaller letter after a larger one. Swapping b/a makes bar become abr, and swapping r/i makes rim become irm, which is smaller even though it is not sorted.
Example 2
names = ["aa","z",""]return = [false,false,false]Equal-letter swaps do not change aa. A one-character or empty name has no pair of positions.
Example 3
names = ["ba","ab","cba"]return = [true,false,true]ba and cba can move a smaller later letter to an earlier position; ab is already nondecreasing.
Constraints
0 <= names.length <= 100.0 <= names[i].length <= 1000; total username length is at most5000.- All characters are lowercase English letters.
More Roblox Online Assessment questions
- Centered Block Placement QueriesOA · Seen Oct 2026
- Robot Navigation Around LasersOA · Seen Oct 2026
- Factory Batch Profit (Game Adaptation)OA · Seen Sep 2026
- Nested Recipe Blocks (Game Adaptation)OA · Seen Sep 2026
- Vehicle Builds for Required Terrain (Game Adaptation)OA · Seen Sep 2026
- Track Received Byte RangesOA · Seen Sep 2026
- Inventory Discount TrackerOA · Seen Sep 2026
- Break a PalindromeOA · Seen Jun 2026
- Count Pairs Differing in One DigitOA · Seen Oct 2025
- Find Zero Cells in a 2×2 GridOA · Seen Oct 2025
Similar questions at other companies
- Maximum Ones After K OperationsGoldman Sachs · OAGoldman Sachs interview questions
- Minimum Operations to Reduce a Transaction LedgerVisa · OAVisa interview questions
- Prepare NotificationMicrosoft · OAMicrosoft interview questions
- Minimum Changes for Distinct Adjacent CharactersHeadlands Technologies · OAHeadlands Technologies interview questions
- Largest Number With Even Digit FrequenciesDRW · OADRW interview questions
- Minimum Replacements for Unequal Adjacent CharactersIBM · OAIBM interview questions
- Crop Text at a Whole-Word BoundaryAmerican Express · OAAmerican Express interview questions
- Minimum Flips for Even Binary RunsJP Morgan Chase · OAJP Morgan Chase interview questions
- Missing WordsVanguard · OAVanguard interview questions
- Digit Changes for a Multiple of 9Nutanix · OANutanix interview questions