FastPrepFastPrep
Problem Brief

Similar Password 🪴 (Singapore)

INTERNOA

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 Description

Complete the function countMinimumOperations in the editor below.

countMinimumOperations has the following parameter:

  • string password: the password

Returns

int: the minimum number of operations

1Example 1

Input
password = "hack"
Output
1
Explanation
The '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.

2Example 2

Input
password = "abcd"
Output
1
Explanation
In one operation, 'd' can be changed to 'e'. The resultant string is "abce" which has an equal number of vowels and consonants.

3Example 3

Input
password = "bigbangt"
Output
2
Explanation
In 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

Limits and guarantees your solution can rely on.

Unknown for now
public int countMinimumOperations(String password) {
  // write your code here
}
Input

password

"hack"

Output

1

Sign in to submit your solution.