AlienAndPassword
SRM 605 · 2013-12-22 · by Witaliy
Problem Statement
Alien Fred wants to destroy the Earth, but he forgot the password that activates the planet destroyer.
You are given a
Return the number of different passwords Fred needs to try.
Constraints
- S will contain between 1 and 50 characters, inclusive.
- Each character in S will be an uppercase English letter ('A'-'Z').
"A" Returns: 1
In this case, the only password Fred needs to try is an empty string.
"ABA" Returns: 3
The following three passwords are possible in this case: "BA", "AA", "AB".
"AABACCCCABAA" Returns: 7
"AGAAGAHHHHFTQLLAPUURQQRRRUFJJSBSZVJZZZ" Returns: 26
"ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ" Returns: 1
Regardless of which character we erase, we will always obtain the same string. Thus there is only one possible password: the string that consists of 49 'Z's.
Submissions are judged against all 64 archived test cases, of which 5 are shown here. Case numbers match the judge’s.
Language: C++17 · define a public class AlienAndPassword with a public method int getNumber(string S) · 64 test cases · 2 s / 256 MB per case