Question: Usernames Changes A company has released a new internal system, and each employee has been assigned a username. Employees are allowed to change their usernames
Usernames Changes
A company has released a new internal system, and each employee has been assigned a username. Employees are allowed to change their usernames but only in a limited way. More specifically, they can choose letters at two different positions and swap them. For example, the username "bigfish" can be changed to "gibfish" swapping and or "bighisf" swapping and The manager would like to know which employees can update their usernames so that the new username is smaller in alphabetical order than the original username.
For each username given, return either "YES" or NO based on whether that username can be changed with one swap to a new one that is smaller in alphabetical order.
Note: For two different strings A and of the same length, is smaller than in alphabetical order when on the first position where A and differ, A has a smaller letter in alphabetical order than has.
For example, let's say usernames bee "superhero", "ace" For the first username, "bee", it is not possible to make one swap to change it to a smaller one in alphabetical order, so the answer is NO For the second username, "superhero", it is possible get a new username that is smaller in alphabetical order for example, by swapping letters and to get "hupersero" so the answer is "YES". Finally, for the last username "ace", it is not possible to make one swap to change it to a smaller one in alphabetical order, so the answer is NO Therefore you would return the array of strings NO "YES", NO
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
