FastPrepFind Password Strength

Find Password Strength

Amazon logoAmazon● MediumOA

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 = 3

One 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 <= 10
  • credential has only lowercase English letters ('a' to 'z')

More Amazon interview questions

Similar questions at other companies

Interview reports that mention this question

Amazon interview experiences

See Amazon hiring insights
Saved
class Solution {
    public int findPasswordStrength(String credential) {
      // write your code here
    }

}
Checking account…