Šimon Tóth’s Post

View profile for Šimon Tóth

C++ Educational Content Creator | 20 years of Software Engineering experience distilled into digestible daily posts

Tuesday common C++ interview problem: Construct a binary tree from preorder and inorder traversals. Given the preorder and inorder traversals (both as std::span<int>), construct the corresponding binary tree. Use the add_node(int) method on the provided tree object and return the root node. Solve it yourself: https://lnkd.in/en7G93vC Solution: https://lnkd.in/eZ9MT4yG #cpp #cplusplus #coding #programming #dailybiteofcpp

  • shape, arrow
Chris Ryan

ISO/IEC JTC1/SC22/WG21 - The…11K followers

2y

I actually did have an post-order/in-order tree reconstruction problem as an interview question many years ago.  Many years before span. That is an interesting twist for a solution. I did it the old pointer based way back then (could have used indexes) but I did templatize the data type. Also for the 'fun' of it my solution used a functor type monad with a hidden friend streaming operator to drive the print order. godbolt.org/z/zso9dMrda

To view or add a comment, sign in

Explore content categories