Stack Exchange network consists of 183 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.
Ask questions, find answers and collaborate at work with Stack Overflow for Teams.
Ask questions, find answers and collaborate at work with Stack Overflow for Teams. Explore Teams
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
#Pyth, 30 25 bytes
jb.eu_GkbceQs*R/*FQ4"EDMC
Live demo and all test cases.
Cut off 5 bytes thanks to @Jakube!
Same algorithm as my K answer...but a lot shorter.
30-byte version:
jb.e?%k2_bbcjkm*/*FQ4d"EDMC"hQ
Live demo and all test cases for 50-byte version.
#Pyth, 3030 25 bytes
jb.e?%k2_bbcjkm*eu_GkbceQs*R/*FQ4d"EDMC"hQ*FQ4"EDMC
Same algorithm as my K answer...but 31 bytesa lot shorter.
#Pyth, 30 bytes
Same algorithm as my K answer...but 31 bytes shorter.
jb.e?%k2_bbcjkm*/*FQ4d"EDMS"hQ*FQ4d"EDMC"hQ
Live demo and all test casesLive demo and all test cases.
jb.e?%k2_bbcjkm*/*FQ4d"EDMS"hQ