We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Happy Ladybugs
Happy Ladybugs
Sort by
recency
|
523 Discussions
|
Please Login in order to post a comment
Here is my c++ solution, you can watch the explanation here : https://youtu.be/khDcPEl6to0
Here is my Python solution! If we have at least one empty square, then we can move any of the ladybugs anywhere. This means that the only cases that work are if there are more than one empty square and an even number of each type, or if there are no empty squares but all the ladybugs are already happy.
your code says yes to this, but it should be a no: ZAABBZ
Python3; After realizing 1 empty field gives you possibility to place any existing color anywhere
I thought about using a map to count the letters, but even then I would have to know when the letters would be out of order and there would be no space to sort them. I chose to simply count how many consecutive letters are present after sorting the array (if there is free space for that)
It's funny, because applying sorting makes solution already worse than O(nlogn) :D It was not that good idea after all
Okay, but performance wasn't my goal to resolve this challange.