• @awice Why is the "in" function is set quicker than a "in" of a list?

• This ignores the fact that due to the usage of a hash map the given bound is only the expected time complexity. To get "real" O(N + G.length) running time you can build an array as a mask. This is also the reason that the problem description states that the elements in the list are values from [0, N - 1] as opposed to just any integers.

• set has O(1) lookup like dictionary
@proenca

• Why the complexity is O(N + G.length) not O(N)?

• Why is [3] a connected component?

• This is probably the worst description of an algorithm, ever :)

• Why is [3] a connected component in the example below?

[0,1,2,3]
[0,1,3]

The expected answer should be 1 and not 2. Isn't it?

• In a list, you need to loop through the list to find a certain element, thus its O(N).
whereas in a HashSet, you find an element by its hashcode, which takes O(1).
@proenca

• For the given example, why is the answer 4? There is only 1 connected component i.e [2,3]

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.