Group Group Group Group Group Group Group Group Group

Chapter 4, Challenge 2 Solution does not match problem description

#1

The problem asks for the middle node to be returned. The example returns a list starting at the middle node. Not quite the same thing. :slight_smile:

#2

On a related note, since lists conform to the Collection protocol which has a count property, wouldn’t it be simpler to return list.node(at: list.count / 2)? (I know, it avoids using the list structure being taught :wink:)

#3

I know the node/list duality is a little ambiguous, I’m open to suggestions :slight_smile:

An idea I’ve had is to instantiate a brand new node with the same value as the middle node, but then I would argue that isn’t the real “middle node” of the list.

Note that list.count is O(n) and node(at:) is also O(n).

#4

Thanks Kevin, I had forgotten that count is O(n).