Can someone from code guru correct and respond?
linkedList.add() appends at the end of the linked list. This means it will first need to reach the end of list and then append, which is O(N^2) for each row where lefttoRight is false. unless java implementation remember the end of the list?
Adding at the front is o(1) because linked list knows the root.
Course: Grokking the Coding Interview: Patterns for Coding Questions - Learn Interactively
Lesson: Zigzag Traversal (medium) - Grokking the Coding Interview: Patterns for Coding Questions