Welcome to my personal website. I use this space to share some of my thoughts and software that I write in my free time. Sometimes I also publish photos. If you want to get in touch please use LinkedIn or Mastodon.
Leetcode: Binary tree zigzag level order traversal
Traverse a tree where the root node is given with a zig-zag level and return the values in a list with one entry per level. For example:
This can be achieved with the same BFS algorithm from before, with an additional introduction of a reverse boolean variable. If the order is reversed, the output values are prepended instead of appended. After each level, the reverse variable is toggled via reverse = not reverse.
About the author
Friedrich Ewald is an experienced Software Engineer with a Master's degree in Computer Science. He started this website in late 2015, mostly as a digital business card. He is interested in Go, Python, Ruby, SQL- and NoSQL-databases, machine learning and AI and is experienced in building scalable, distributed systems and micro-services at multiple larger and smaller companies.