Ctrl K

The Sticky Key

Easy
Anya's keyboard sometimes sticks: one press of a key can print that letter several times in a row. She knows this happened **at most once** while she was typing (one key, on one press), and possibly not at all. You get the string screen: what ended up on the screen. Return how many different strings Anya could have meant to type.
Example 1
screen='coffee' → 3

Either the "f" stuck (the intent was "cofee"), or the "e" did ("coffe"), or nothing stuck at all: three options.

Example 2
screen='zzzz' → 4

The intended text could be "z", "zz", "zzz" or "zzzz".

Example 3
screen='plan' → 1
Constraints
  • 1 ≤ len(screen) ≤ 100
  • screen consists of lowercase English letters
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsValue of a Roman Numeral EasyShared Start of Words EasyBracket Balance EasyWhere the Fragment Starts EasyLength of the Final Word Easy
loading Python…
Input
screen='coffee'
Expected
3

Run checks the first 3 tests in your browser. Submit checks all 54 tests on the server, hidden ones included.