Similar Password 🪴 (Singapore)
Updated
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
More PayPal interview questions
- Minimum Cost to Merge Values into OneOA · Seen Nov 2026
- Per-User Sliding-Window Rate LimiterOA · Seen Nov 2026
- Total Cost Against the Lowest Earlier PriceOA · Seen Nov 2026
- Can the Singer Perform the Song?PHONE SCREEN · Seen Jul 2025
- Items Purchase (For Java Backend Engineer)OA · Seen Nov 2024
- Find Minimum Price to SpendOA · Seen Oct 2024
- Modify ArrayOA · Seen Jun 2024
- Count User Logins 🌿 (Singapore)OA · Seen Mar 2024
Similar questions at other companies
- Minimum No-Repeat Segments After One Character RemovalSalesforce · OASalesforce interview questions
- Longest Non-Decreasing Substring After Pair SwapsVisa · OAVisa interview questions
- Minimum Deletion Cost for Distinct Adjacent CharactersHSBC · OAHSBC interview questions
- Minimum Binary Swaps to a PalindromeAT&T · OAAT&T interview questions
- Robot Assembly Line ConflictsGoogle · OAGoogle interview questions
- Substring RemovalJP Morgan Chase · OAJP Morgan Chase interview questions
- Minimum Additions to Make a Valid ABC StringIBM · OAIBM interview questions
- Maximize Workday EarningsCitadel · OA · PHONE SCREEN · ONSITE INTERVIEWCitadel interview questions
- Minimum Adjacent TranspositionsEpic · OAEpic interview questions
- Maximum String OperationsMicrosoft · OAMicrosoft interview questions