[Question/Problem Statement is the Adapted from HackerRank]
Algorithms/Data Structures — [Problem Solving]
There is a Specific Need for Changes in a List of Usernames. In a given List of Usernames — For Each Username — If the Username can be Modified and Moved Ahead in a Dictionary. The Allowed Modification is that Alphabets can change Positions in the Given Username.
Example
usernames[] = {"Aba", "Cat"}
"Aba" can be Changed to only "Baa" — Hence, It can Never Find a Place Ahead in the Dictionary. Hence, Output will be "NO". "Cat" can be Changed to "Act", "Atc", "Tca", "Tac", "Cta" and Definitely "Act" will Find a Place Before "Cat" in the Dictionary. Hence, Output will be "YES".
[Function Description]
Complete the function possibleChanges in the Editor Below.
possibleChanges has the Following Parameters:
String usernames[n]: An Array of User Names
Returns String[n]: An Array with "YES" or "NO" Based on Feasibility
(Actual Question Says String Array, But Signature is List of Strings)
Constraints
• [No Special Constraints Exist, But Cannot Recall Exactly]
Input Format
"The First Line Contains an Integer, n, the Number of Elements in Usernames.",
"Each Line of the n Subsequent Lines (where 0 < i < n) contains a String usernames[i]."
[Sample Case 0 — Sample Input For Custom Testing]
5
Aba
Cat
Boby
Buba
Bapg
Sungi
Lapg
Acba
Sample Output (Each Should Be on a Separate Line)
NO YES NO YES YES YES YES YES
[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]
As a Software Engineer, the mind is trained to seek optimizations in every aspect of development and ooze out every bit of available CPU Resource to deliver a performing application. This begins not only in designing the algorithm or coming out with efficient and robust architecture but right onto the choice of programming language. Most of us, as we spend years in our jobs — tend to be proficient in at least one of these.
Recently, I spent some time checking on the Performance (not a very detailed study) of the various programming languages. One, by researching on the Internet; Two, by developing small programs and benchmarking. The legacy languages — be it ASM or C still rule in terms of performance. But these are definitely ruled out for enterprise applications due to the complexity in development, maintainability, need for object orientation, and interoperability. They still will win for mission-critical or real-time systems, which need performance over these parameters. There were languages I briefly read about, including other performance comparisons on the internet. These include Python, PHP, Perl, and Ruby. Considering all aspects and needs of current enterprise development, it is C++ and Java which outscore the other in terms of speed. According to other comparisons [Google for 'Performance of Programming Languages'] spread over the net, they clearly outshine others in all speed benchmarks. So much for my blog title :-) So when these titans are pit against each other in real-time, considering all aspects of memory and execution time — Java is floored. Though I have spent the last ~17 years (In 2021) of my life coding and perfecting my Java and J2EE skill — I suddenly feel... Ahem, Slow! One of the problem statements to verify this is given below (along with the associated code) and the associated execution parameters.
[Disclaimer: Problem Statement given below is the property of www.codechef.com
]
In Byteland they have a very strange monetary system. Each Bytelandian gold coin has an integer number written on it. A coin n can be exchanged in a bank into three coins: n/2, n/3, and n/4. But these numbers are all rounded down (the banks have to make a profit). You can also sell Bytelandian coins for American dollars. The exchange rate is 1:1. But you can not buy Bytelandian coins. You have one gold coin. What is the maximum amount of American dollars you can get for it? Input The input will contain several test cases (not more than 10). Each test case is a single line with a number n, 0 <= n <= 1 000 000 000. It is the number written on your coin.
JAVA SOLUTION (Will Be Uploaded Later)
C++ SOLUTION (Will Be Uploaded Later)
RESULTS