Skip to content

Conversation

@shirley1chu
Copy link

No description provided.

Copy link

@CheezItMan CheezItMan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work, I like how you did the bonus BFS method. Do note that recursion does impact space complexity. Otherwise this is outstanding!

# Time Complexity:
# Space Complexity:
# Time Complexity: O(logn)
# Space Complexity: O(1)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since you're using a recursive add_node helper method, you are using the system stack and this impacts space complexity. Since you are making O(log n) recursive calls on a balanced tree this would have a space complexity of O(log n).

return 0 unless node
left_counter = height_counter(node.left)
right_counter = height_counter(node.right)
counter = left_counter > right_counter ? left_counter : right_counter

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

i += 1
current = array[i]
end
return array.map do |node|

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good use of map

# Time Complexity:
# Space Complexity:
# Time Complexity: O(n)
# Space Complexity: O(2n)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In Big-O we drop the coefficient so this should be Space complexity of O(n)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants