educative.io

The PopBack() function in Deque has a small piece of dead code

The append call is unnecessary, here is an improved version:

// PopBack will pop an element from the back of the dequeue
func (s *Deque) PopBack() int { 
     i := len(s.items) - 1 
     defer func() { 
        s.items = s.items[:i]
     }()
     return s.items[i] 
}    

Course: Grokking Coding Interview Patterns in Go - Learn Interactively
Lesson: Find Maximum in Sliding Window - Grokking Coding Interview Patterns in Go


Course: Grokking Coding Interview Patterns in Go - Learn Interactively
Lesson: Find Maximum in Sliding Window - Grokking Coding Interview Patterns in Go

Hi @Wallace_Wang ,

Thank you for reaching out to us with your suggestion. We are always open to new ideas and ways of solving problems, and it’s great to see that you share that same spirit of innovation and learning.

Regarding the implementation of the Deque, we recently updated the entire implementation to make it more efficient with regards to time complexity. This update has changed the entire Deque implementation and it no longer has an append call in the PopBack() function.

We would still like to thank you for giving feedback on our code. If you have any confusions or questions, please feel free to ask us. Have an amazing experience learning the Educative way!