kamyu104/LeetCode-Solutions

The corner case in 488. Zuma Game

thisistt opened this issue · 1 comments

When I surfing the discussion about 488. Zuma Game, I notice that someone point out the corner case.
This special case is like following :

board : "WWRRWWBBWW"
hand : "RB"

If you list all possible case, it should retrun "2".
Solution as following:

board : "WWRRWWBBWW"
hand : "RB"
->
board : "WWRRWWBBWRW"
hand : "B"
->
board : "WWRRWWBBBWRW"->"WWRRWWWRW"->"WWRRRW"->"WWW"->""
hand : ""

However, the official solution can not pass this case neither.
image
The key point is that most of algorithm (including the c++ & python solution in this repo) will insert the balls with the same color. But the corner case show that it is not perfect algorithm for reducing the complexity.

Yes, you are right. Thanks for your reminding.
As the corner case was discussed in the Leetcode forum, for this problem, it should either relax the time limit or add a description that ball can be only inserted beside a ball with same color.
Currently, I don't come up with any better solution other than brute force to pass in time.