We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
This is actually less efficient since pop(0) is an O(n) operation in python. Removing from the front of a list (as opposed to the end) is highly inefficient. The other solution above using deque is actually better than this since deques are optimized for constant time pops and appends from both ends.
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Tree: Level Order Traversal
You are viewing a single comment's thread. Return to all comments →
This is actually less efficient since pop(0) is an O(n) operation in python. Removing from the front of a list (as opposed to the end) is highly inefficient. The other solution above using
deque
is actually better than this since deques are optimized for constant time pops and appends from both ends.