Consider lines of slope -1 passing between nodes. Given a Binary Tree, print all diagonal elements in a binary tree belonging to same line. In the above example lines of slope -1 are passed between nodes and the diagonal traversal will be:2 5 9 7 6 11 4 2 5 Solution Pre-requisite: ...
Practice this problem Recursive Version We can easily solve this problem with the help ofhashing. The idea is to create an empty map where each key in the map represents a diagonal in the binary tree, and its value maintains all nodes present in the diagonal. Then performpreorder traversalon...