02. Remove Colored Pieces if Both Neighbors are the Same Color
Last updated
Was this helpful?
Last updated
Was this helpful?
The problem can be found at the following link:
Initialize scores for Alice and Bob (aliceScore
and bobScore
) to zero
.
Iterate through the colors (excluding edge pieces) using a loop. For each piece in the iteration:
Check if it's A and its neighboring pieces are also A. If yes, increment aliceScore
as Alice can remove the current piece.
Check if it's B and its neighboring pieces are also B. If yes, increment bobScore
as Bob can remove the current piece.
Return true
if Alice's score is greater
than Bob's score; otherwise, return false
.
Time Complexity: O(n)
Auxiliary Space Complexity: O(1)
For discussions, questions, or doubts related to this solution, please visit our . We welcome your input and aim to foster a collaborative learning environment.
If you find this solution helpful, consider supporting us by giving a ⭐ star
to the repository.