TORONTO KIDS COMPUTER CLUB | Monday 20:00 Python Practice 21.03.29.
post-template-default,single,single-post,postid-19242,single-format-standard,ajax_fade,page_not_loaded,,qode-theme-ver-7.6.2,wpb-js-composer js-comp-ver-6.10.0,vc_responsive

Monday 20:00 Python Practice 21.03.29.

02 Apr Monday 20:00 Python Practice 21.03.29.

Steve has a string of lowercase characters in range ascii[‘a’..’z’]. He wants to reduce the string to its shortest length by doing a series of operations. In each operation he selects a pair of adjacent lowercase letters that match, and he deletes them. For instance, the string aab could be shortened to b in one operation.

Steve’s task is to delete as many characters as possible using this method and print the resulting string. If the final string is empty, print “Empty String” without quotes.

characters can be deleted only if they form a pair and are same(for example: from aaa we can only delete 2 a’s and will be left with a single a).

Input Specification:
A single string, s.


Output Spicification:
If the final string is empty, print Empty String; otherwise, print the final non-reducible string.

Sample Input

Sample Output

Steve performs the following sequence of operations to get the final string:
aaabccddd -> abccddd -> abddd -> abd

No Comments

Post A Comment