Username Change
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.