[M💙 Challenge] Alphabetical Balance Scale 🔠⚖️ | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 30

[M💙 Challenge] Alphabetical Balance Scale 🔠⚖️

Monday Blue 💙 Challenge Series #14 Let's play with alphabets this week! This time we will need to put alphabets onto the balance scale at 2 ends to achieve equilibrium. If it's impossible to do so, determine the letter need to be added with minimum weight. The letters weight from 1 to 26 which corresponds to A to Z respectively. 💼 TASK Write a program to accept a string of uppercase letters and split into 2 groups which produce the minimum sum difference by using an underscore character "_". If the sum difference is not ZERO, we will need to add a letter (surround it with round brackets) on either side to achieve equilibrium. 🔧 TEST CASE "A" ➡ (A)_A or A_(A) "AA" ➡ A_A "AAA" ➡ A(A)_AA or AA_A(A) "ABC" ➡ AB_C "ABBA" ➡ AB_BA "ABCD" ➡ ABC_D(B) "ZEPHYRKOO" ➡ ZEPHY_RKOO(U) "MONDAYBLUE" ➡ MONDA(R)_YBLUE "CHRISTMAS" ➡ CHRIS_TMAS(D) "IS" ➡ I(J)_S "COMING" ➡ COM_ING(A) "SOON" ➡ SO_ON(E) ❤ BONUS Clear-cut and optimized approach is encouraged. Happy Coding!!! 😁💻

19th Dec 2017, 12:46 AM
Zephyr Koo
Zephyr Koo - avatar
94 Answers
+ 8
So ... Finally I wrote the correct one : https://code.sololearn.com/c180VkDulLz4/#py
20th Dec 2017, 12:17 PM
Cépagrave
Cépagrave - avatar
+ 25
Sorry, I'm late. But the good news is that my Python code works!!!! https://code.sololearn.com/cO5y1JT41Up5/?ref=app
18th Dec 2017, 4:10 PM
Justine Ogaraku
Justine Ogaraku - avatar
+ 17
This was harder than I thought. https://code.sololearn.com/W506vsSzOpM3/?ref=app
18th Dec 2017, 4:15 PM
Swapnil Srivastava
Swapnil Srivastava - avatar
18th Dec 2017, 4:49 PM
qwerty
qwerty - avatar
+ 17
Oh wow I just noticed there are some constructive arguments happening here! Personally I believe that everyone have the right to share anything they want and it's up to our own to take it or leave it as one man's trash (incomprehensible code) can be another man's treasure (enlightment). I would rather have a few people that really understand or get inspired from my code instead of the sheer number of likes and I believe there are others feel the same as well. So no worry how others think about it as there are still some people will find it useful. There are abundant of knowledge over here but unfortunately time is limited, therefore pick the one that worth your time and leave the rest for others. 😉
19th Dec 2017, 3:30 PM
Zephyr Koo
Zephyr Koo - avatar
+ 16
Challenge accepted.
18th Dec 2017, 1:39 PM
qwerty
qwerty - avatar
+ 16
@Pegagus Not really if you really look into the problem. I always try my best to make sure the challenge is suitable for fresh programmers and this one is no exception, hopefully. 😉
18th Dec 2017, 1:52 PM
Zephyr Koo
Zephyr Koo - avatar
+ 16
My try, sorry I'm late was busy today https://code.sololearn.com/cR03M5KT7zyz/?ref=app
18th Dec 2017, 8:35 PM
David Akhihiero
David Akhihiero - avatar
+ 15
Here's my try Tell me if something's wrong. I have tried to show every possible case! https://code.sololearn.com/cOxLMXAJpEA2/?ref=app
18th Dec 2017, 2:30 PM
Kartik
Kartik - avatar
+ 15
@Calvin I think you should give the one in which minimum valued alphabet is added. Example: If you have added B in one and in other you have added C, then, you should print the one where you added B as B is smaller than C.
18th Dec 2017, 3:35 PM
Kartik
Kartik - avatar
+ 15
Challenge accepted!!
18th Dec 2017, 3:35 PM
Justine Ogaraku
Justine Ogaraku - avatar
19th Dec 2017, 9:11 AM
Käzî Mrîdùl Høssäîn
Käzî Mrîdùl Høssäîn - avatar
+ 14
Edit: I have added my code.
19th Dec 2017, 9:24 AM
Swapnil Srivastava
Swapnil Srivastava - avatar
+ 14
Beautiful challenge, thank you 😊 https://code.sololearn.com/c3g25H6xjKaw/?ref=app
19th Dec 2017, 11:14 AM
LukArToDo
LukArToDo - avatar
+ 14
Guys I'm really amazed by your thought process here and never think that this problem leads to overthinking and become such complicated! 💭 Please be reminded that we are using a balance scale instead of finding the pivot point so we just need both the LEFT and RIGHT group to put on the plates and balance it by adding a minimum weight, if required. 😉
19th Dec 2017, 6:00 PM
Zephyr Koo
Zephyr Koo - avatar
+ 14
Indeed! We preserve the order in this case to reduce the complexity instead of picking up one-by-one. You guys are pretty awesome with such amazing ideas! Any advanced solution is welcome but I'll pick the the best answer based on the requirement above to be fair. Thank you everyone again! 😄
20th Dec 2017, 3:49 AM
Zephyr Koo
Zephyr Koo - avatar
+ 13
@JPM7 Yes it matters as we need to ensure the added weight is minimum. For example, "ABC" ❌ A(D)_BC ✔️ AB_C ❌ (F)_ABC or ABC_(F)
18th Dec 2017, 2:08 PM
Zephyr Koo
Zephyr Koo - avatar
+ 13
@Cpasgrave I don't think you can change the order of the alphabets!🤔 Check @Zephyr Koo's given test cases again.
20th Dec 2017, 3:08 AM
Kartik
Kartik - avatar
+ 13
@Cpasgrave Yeah, what you made is definitely complicated than the actual one!
20th Dec 2017, 3:34 AM
Kartik
Kartik - avatar
+ 12
@Pegasus Nope as the added letter weight is not the minimum possible. We can achieve equilibrium by adding "B" instead of "D". I wish to provide an explanation but worry it will produce an anchoring effect for the algorithms submitted. I believe you can do well after study the problem a little bit more. Keep it up! 😉
18th Dec 2017, 2:00 PM
Zephyr Koo
Zephyr Koo - avatar