DZone
[Question/Problem Statement is the Adapted from HackerRank]
[Function Description]
Complete the function possibleChanges in the Editor Below.
String usernames[n]: An Array of User Names
(Actual Question Says String Array, But Signature is List of Strings)
• [No Special Constraints Exist, But Cannot Recall Exactly]
Input Format
“The First Line Contains an Integer, n, the Number of Elements in Usernames.”,
[Sample Case 0 — Sample Input For Custom Testing]
5
Aba
[Explanation of the Solution]
This is again a Good Question from Hacker Rank to Test Your Logic / Problem Solving Abilities. The Core Point to Handle is that For Each Combination of 2 Alphabets that Exists in the Username String > We Need to Check if the Latter Occurring Character (ASCII) is Less than the Former Occurring Character (ASCII). For Example in the String “Bapg” — For a Selection of “Ba” from “Bapg” — We have “a” Occurring Before “B” in the English Alphabet. We can Have Two Loops (One Nested) to Decide for a Combination of Each Two Alphabets. The Time Complexity of this Solution is O(n^2).
[Source Code, Sumith Puri (c) 2021 — Free to Use and Distribute]
Source: DZone