+ 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!!! 😁💻
47 Réponses
+ 7
my one https://code.sololearn.com/WqY0Mpmk0EcF/?ref=app
with deepest level and if string inside
+ 13
Here is mine:
https://code.sololearn.com/WFHrJhu8cL9k/#html
+ 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. 😉
+ 8
Good try @matmozaur! However the program failed to validate ((>][<)). Can you please try again? 😉
+ 8
@matmozaur You're welcome! You're getting closer now, please try ))(( as well. 👍
+ 8
@Zizibee, as mentioned above count only is not enough. 😉
+ 8
@Zizibee Please check my updated test cases above. 😉
+ 8
I think my second try is better. It wasn't that easy I thought first:
https://code.sololearn.com/chh87oR3aIdF/?ref=app
+ 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. 👍
+ 7
there you go.
https://code.sololearn.com/cLrmTvW1u4R7/?ref=app
+ 7
@sayan Well done! How about the degree computation? 😉
+ 7
@sayan Great and thanks for your submission! 😁
+ 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! 😄
+ 6
@Zizibee Almost there just left with an off-by-one error! 😉
+ 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
+ 5
Oh yeau right
+ 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
+ 5
@Tyzone Another nice Python submission! 👍
+ 5
Well done we got another solution in C++ by Hello world!
+ 4
Maybe this :D?
https://code.sololearn.com/cmY9p7ItgBJT/#cpp