+ 22

🏆 [Challenge] To Wrap or Not To Wrap

Let's assume we can perform wrapping with:- 🔘 (Round brackets) 🔘 [Square brakcets] 🔘 <Angle brackets> Write a program to check if a given string was wrapped properly with the characters above. Test cases: ✅ (()<<[]>>) ✅ <<>>() ✅ ()<>[] ✅ [[<<(())>>]] ❎((<>>[]) ❎(><) ❎ (<)> ❎))(( Sounds easy? 😉 EXTRA: Display the "Degree of Wrap" by identify the nesting level (deepest) for valid string as well. For example, the degree for the test cases above would be 3, 1, 0 & 5 respectively. Happy coding!!! 😁💻

20th Sep 2017, 3:23 PM
Zephyr Koo
Zephyr Koo - avatar
47 Réponses
+ 7
my one https://code.sololearn.com/WqY0Mpmk0EcF/?ref=app with deepest level and if string inside
13th Sep 2017, 1:21 PM
ysraelcon
ysraelcon - avatar
14th Sep 2017, 7:42 AM
Nikolay Nachev
Nikolay Nachev - avatar
+ 9
I see, sorry for double posting as I didn't noticed it and this is my 1st challenge invite. Regarding your idea, count is not really enough as [<]> was considered invalid. 😉
13th Sep 2017, 10:12 AM
Zephyr Koo
Zephyr Koo - avatar
+ 8
Good try @matmozaur! However the program failed to validate ((>][<)). Can you please try again? 😉
13th Sep 2017, 10:57 AM
Zephyr Koo
Zephyr Koo - avatar
+ 8
@matmozaur You're welcome! You're getting closer now, please try ))(( as well. 👍
13th Sep 2017, 11:22 AM
Zephyr Koo
Zephyr Koo - avatar
+ 8
@Zizibee, as mentioned above count only is not enough. 😉
13th Sep 2017, 11:36 AM
Zephyr Koo
Zephyr Koo - avatar
+ 8
@Zizibee Please check my updated test cases above. 😉
13th Sep 2017, 11:59 AM
Zephyr Koo
Zephyr Koo - avatar
+ 8
I think my second try is better. It wasn't that easy I thought first: https://code.sololearn.com/chh87oR3aIdF/?ref=app
13th Sep 2017, 12:55 PM
Zizibee
+ 8
@ysraelcon Impressive solution with regex! I always believe Javascript submission is superior compared to other languages due to the absence of data structure with pure logic. 👍
13th Sep 2017, 4:54 PM
Zephyr Koo
Zephyr Koo - avatar
14th Sep 2017, 2:36 AM
Hello world
+ 7
@sayan Well done! How about the degree computation? 😉
21st Sep 2017, 5:17 AM
Zephyr Koo
Zephyr Koo - avatar
+ 7
@sayan Great and thanks for your submission! 😁
21st Sep 2017, 5:52 AM
Zephyr Koo
Zephyr Koo - avatar
+ 6
@Zizibee Great you've made it finally! Your solution is similar to mine in C# as the traditional approach was using Stack. I'm still planning an alternative without Stack and going to publish after I receive more than 5 submissions here. Now go ahead and try to display the degree as well! 😄
13th Sep 2017, 4:58 PM
Zephyr Koo
Zephyr Koo - avatar
+ 6
@Zizibee Almost there just left with an off-by-one error! 😉
13th Sep 2017, 11:20 PM
Zephyr Koo
Zephyr Koo - avatar
+ 6
Here's my attempt with C#. Meanwhile I'm still finding an alternative way to solve it by trying to determine if we can find out the parity based on index. Any ideas are welcome! 😄 https://code.sololearn.com/cf0k6K2B6gvC/?ref=app
14th Sep 2017, 8:50 AM
Zephyr Koo
Zephyr Koo - avatar
+ 5
Oh yeau right
13th Sep 2017, 10:13 AM
👑 Prometheus 🇸🇬
👑 Prometheus 🇸🇬 - avatar
+ 5
You right @Zephyr Koo, it's required one more check on every iteration, now it shuld work https://code.sololearn.com/cmY9p7ItgBJT/#cpp thx
13th Sep 2017, 11:08 AM
matmozaur
matmozaur - avatar
+ 5
@Tyzone Another nice Python submission! 👍
13th Sep 2017, 11:17 PM
Zephyr Koo
Zephyr Koo - avatar
+ 5
Well done we got another solution in C++ by Hello world!
14th Sep 2017, 5:31 AM
Zephyr Koo
Zephyr Koo - avatar
13th Sep 2017, 10:18 AM
matmozaur
matmozaur - avatar