+ 4

String palindrome via alphebetical compression

Given a string consists of multiple alphabets, if its not a palindrome, compress TWO consecutive alphabets by value. a =>1 b=>2 .... The compression may occur more than once, given different situations. If no possible compression can be made, give an appropriate message. For example: baaa should return ba(b) dcad should return d(d)d abab should return (c)(c) jead & js should return not available for dual alphabetical compression Compression resulting in a single alphabet will not be considered.

15th Feb 2018, 10:25 AM
Ng Ju Ping
Ng Ju Ping - avatar
5 Antworten
+ 3
Bonus: for some special cases, such as jead, will require triple compression where three alphabets are compressed: jead should be j(j) in this way. Make the code available for the following examples as well: abei should return (i)i acbzdaa should return (f)z(f). Good Luck, and have fun coding.
15th Feb 2018, 10:27 AM
Ng Ju Ping
Ng Ju Ping - avatar
+ 3
there are many constraints missing, baaa => ba ( aa) => ba(b) started from right end dcad => d(ca)d => d(d)d started from middle acbzdaa => (ac)bzd(aa) => (d) bzd(b) => (db)z(db) => (f)z(f) started from both ends, need more clarification
15th Feb 2018, 12:24 PM
Morpheus
Morpheus - avatar
+ 2
Any kind of suggestion is encouraged to enhance this question after moderate consideration.
15th Feb 2018, 10:29 AM
Ng Ju Ping
Ng Ju Ping - avatar
+ 2
sayan if ba get compressed to c the final string would be caa which isnt a palindrome
15th Feb 2018, 10:54 AM
Ng Ju Ping
Ng Ju Ping - avatar
+ 1
baaa its not pal. why ba didnt get compressed as c????
15th Feb 2018, 10:37 AM
sayan chandra
sayan chandra - avatar