We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
- Prepare
- Data Structures
- Trees
- Tree : Top View
- Discussions
Tree : Top View
Tree : Top View
Sort by
recency
|
957 Discussions
|
Please Login in order to post a comment
public static void topView(Node root) { if (root == null) { return;
Queue> queue = new LinkedList<>(); // Map to store the first node at each horizontal distance Map map = new TreeMap<>();
from collections import deque def topView(root): if(root==None): return 0 hd_map = {}
DFs:
public static void top(Node root,Map m,int w,int h){
}
public static void topView(Node root) {
By top view does it mean by top view? From provided example it looks like it traversed only right child only, and the there was no left child in the sample input and output provided. So in case of presence of left child to root will it also traverse left childrens too. In any case I wrote the following java code for traversing left chilrens and right childrens from root and seems to work for base testcase:
Please suggest improvements to this code. Thanks