Find Password Strength
Updated
Problem statement
Your team at Amazon has a new rule for internal login passwords. A password has only lowercase English letters. It is valid when it has at least one vowel and at least one consonant. The vowels are 'a', 'e', 'i', 'o' and 'u'. All other letters are consonants.
You can cut a password into pieces. Each piece is a run of letters that sit next to each other, in the same order. Every letter belongs to exactly one piece.
The strength of a password is the largest number of pieces you can cut it into so that every piece is a valid password. If the password itself is not valid, its strength is 0.
You are given a password credential. Return its strength.
For example, let credential = "abe". It is valid. Any cut leaves a piece "a" or "e" on its own, and that piece has no consonant. So the only choice is the whole password. The answer is 1.
Function
findPasswordStrength(credential: String) → int
Complete the function findPasswordStrength in the editor.
findPasswordStrength has the following parameter:
String credential: the password
Returns
int: the strength of the password
Examples
Example 1
credential = "hackerrank"return = 3One way is "hack", "er" and "rank". Each piece has a vowel and a consonant. The password has only 3 vowels (a, e, a), and every piece needs one, so 4 pieces are not possible. The answer is 3.
Constraints
1 <= credential.length <= 10credentialhas only lowercase English letters ('a'to'z')
More Amazon interview questions
- LRU Cache for Query ResultsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Maximal SquareONSITE INTERVIEW · Seen Nov 2026
- Serialize and Deserialize a Binary TreeONSITE INTERVIEW · Seen Nov 2026
- Course SchedulePHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Course Schedule IIPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Diagonal Traversal of a Binary TreeONSITE INTERVIEW · Seen Nov 2026
- Minimum Time to Spread Through a GridPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Consistent-Hash Packet RouterPHONE SCREEN · Seen Nov 2026
- Count Connected ComponentsPHONE SCREEN · Seen Nov 2026
- Maximize K-Element AND with an Increment BudgetOA · Seen Nov 2026
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