Skip to main content

Posts

Showing posts with the label top view

Tree : Top View Hackerrank Solution - java

Tree : Top View Hackerrank Solution for explanation watch Video :  Code:  import  java.util.*; import  java.io.*; class  Node {     Node left;     Node right;      int  data;          Node( int  data) {          this .data = data;         left = null;         right = null;     } } class  Solution {      /*           class Node          int data;         Node left;         Node right;     */      static   class  NodeLevel{         Node node;         Integer level;         NodeLevel(Node node,Integer level){              this .node = node;              this .level = level;         }     }      public   static   void  topView(Node root) {         Queue<NodeLevel> q =  new  LinkedList<>();         TreeMap<Integer,Integer> tm =  new  TreeMap<>();          if (root==null){              return ;         }         q.add( new  NodeLevel(root, 0 ));          while (!q.isEmpty()){             NodeLevel temp = q.poll();             Node temp1 = temp.node;             Intege