How to Solve “alphabetSubsequence” in CodeFights

The Problem:

Check whether the given string is a subsequence of the plaintext alphabet.

Example

  • For s = "effg" or s = "cdce", the output should be
    alphabetSubsequence(s) = false;
  • For s = "ace" or s = "bxz", the output should be
    alphabetSubsequence(s) = true.

Input/Output

  • [time limit] 4000ms (py)
  • [input] string sConstraints:
    2 ≤ s.length ≤ 15.
  • [output] booleantrue if the given string is a subsequence of the alphabet, false otherwise.

The Solution:
def alphabetSubsequence(s):
prev = chr(1)
for x in s:
if x<=prev:
return 0
prev = x
return 1

The Explanation:

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s