educative.io

Fails leetcode 924 unit test

I ran your solution code against leetcode 924 and it failed for 1 unit test:

graph: [[1,0,0,0,0,0,0,1,1,1],[0,1,1,0,0,1,0,0,0,0],[0,1,1,1,0,0,1,0,0,0],[0,0,1,1,0,1,1,0,0,0],[0,0,0,0,1,0,0,1,0,1],[0,1,0,1,0,1,1,0,0,0],[0,0,1,1,0,1,1,0,0,0],[1,0,0,0,1,0,0,1,0,1],[1,0,0,0,0,0,0,0,1,1],[1,0,0,0,1,0,0,1,1,1]]

initial: [2,4]

Expected answer: 2
Actual answer: 4


Course: Grokking Coding Interview Patterns in Java - Learn Interactively
Lesson: Solution: Minimize Malware Spread

1 Like

Hello @John_Tavenner,

Thank you for reporting this issue in the solution code. We really appreciate our users when they go above and beyond the normal scope of learning. Switching to a different platform to test our solution code is indeed helpful feedback.

The issue in the solution code lies on line 38 where we are making an incorrect comparison. The comparison should have been based on the values of the initial, whereas right now, we are comparing the indexes, i. It should have been like this:

else if (componentSize == maximumSize && initial[i] < candidateNode)

We’ve incorporated the change, and we’ll let you know once the updated version is live. Feel free to share further suggestions and feedback. We’d be happy to help. Thanks!

Happy learning!