Link to question:
https://leetcode.com/problems/populat...
The last node in the level is len(queue)-1 because python is 0 indexed language. Queue starts with index 0.
Time: O(N) → we process each node exactly once
Space: O(N) → This is a perfect binary tree which means the last level contains N/2 nodes. The space complexity for BFS is the space occupied by the queue which is dependent upon the maximum number of nodes in a particular level. The upper bound on space if it is a regular tree is O(N).