forked from keshavnandan/Topcoder
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAlienAndPassword.txt
65 lines (33 loc) · 1.07 KB
/
AlienAndPassword.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
PROBLEM STATEMENT
Alien Fred wants to destroy the Earth, but he forgot the password that activates the planet destroyer.
You are given a string S.
Fred remembers that the correct password can be obtained from S by erasing exactly one character.
Return the number of different passwords Fred needs to try.
DEFINITION
Class:AlienAndPassword
Method:getNumber
Parameters:string
Returns:int
Method signature:int getNumber(string S)
CONSTRAINTS
-S will contain between 1 and 50 characters, inclusive.
-Each character in S will be an uppercase English letter ('A'-'Z').
EXAMPLES
0)
"A"
Returns: 1
In this case, the only password Fred needs to try is an empty string.
1)
"ABA"
Returns: 3
The following three passwords are possible in this case: "BA", "AA", "AB".
2)
"AABACCCCABAA"
Returns: 7
3)
"AGAAGAHHHHFTQLLAPUURQQRRRUFJJSBSZVJZZZ"
Returns: 26
4)
"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.