Similar Password 🪴 (Singapore)
Problem statement
A password detection system for HackerRank accounts detects a password as similar if the number of vowels is equal to the number of consonants in the password.
Passwords consist of lowercase English characters only, and vowels are ('a', 'e', 'i', 'o', 'u').
To check the strength of a password and how easily it can be hacked, some manipulations can be made to the password. In one operation, any character of the string can either be incremented or decremented. For example, 'f' can be incremented to 'g', or decremented to 'e'. Note that character 'a' cannot be decremented and 'z' cannot be incremented.
Find the minimum number of operations in which the password can be made similar.
Function
countMinimumOperations(password: String) → int
Complete the function countMinimumOperations in the editor below.
countMinimumOperations has the following parameter:
string password: the password
Returns int: the minimum number of operations
Examples
Example 1
password = "hack"return = 1The 'h' can be changed to 'i' in one operation. The resultant string is "iack" which has 2 vowels ('i', 'a') and 2 consonants ('c', 'k') and hence the string is similar. Return 1, the minimum number of operations required.
Example 2
password = "abcd"return = 1In one operation, 'd' can be changed to 'e'. The resultant string is "abce" which has an equal number of vowels and consonants.
Example 3
password = "bigbangt"return = 2In the first operation, the first occurrence of 'b' can be changed to 'a'. In the next operation, another occurrence of 'b' can be changed to 'a'. The resultant string is "aigbangt" which has an equal number of vowels and consonants.
Constraints
Unknown for now