Connection Status:
Competition Arena > AlienAndPassword
SRM 605 · 2013-12-22 · by Witaliy · Brute Force, String Manipulation
Class Name: AlienAndPassword
Return Type: int
Method Name: getNumber
Arg Types: (string)
Problem Statement

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.

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.

Submissions are judged against all 64 archived test cases, of which 5 are shown here. Case numbers match the judge’s.

Coding Area

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

Submitting as anonymous