string puzzles

2 easy string puzzles.

From http://www.careercup.com/question?id=5642266903314432:

Given a mapping configuration such as:

1:a 2:b ... 26:z

And a string like "12632", print the number of different ways you can map such string to alphabet characters.

For example, given "111" the answer is 3 because you can make "aaa", "ak" and "ka" different mappings. However, given "101" the answer is 1 because you can only make "ja" as a possible mapping (01 is not valid).

Python:



From http://www.careercup.com/question?id=6669318070730752:

Given three strings str1, str2 and str3; complete the function to find the smallest subsequence in str1 which contains all the characters in str2 (in any order) and not those in str3.

Sample Test Case: Sample Input:
str1: spqrstrupvqw
str2: sprt
str3: q
Sample Output: strup
Explanation: In the given string str1, the smallest subsequence that contains the characters in str2 ( 's' , 'p' , 'r' , 't' ) and does not contain the character in str3 ( 'q' ) is 'strup'.

In Python:


	        

Leave a comment -

Elliot

https://www.emikek.com

I'm a .NET, PHP, Python, and Javascript developer. Also Project Manager, Scrum Master, and Juilliard trained violist. You cannot connect with me on Facebook, Twitter, or LinkedIn so don't ask.