diff --git a/problems/src/binary_search/MinimumDivisorThreshold.java b/problems/src/binary_search/MinimumDivisorThreshold.java new file mode 100644 index 00000000..89d032d3 --- /dev/null +++ b/problems/src/binary_search/MinimumDivisorThreshold.java @@ -0,0 +1,33 @@ +import java.util.*; +class abc +{ + public static void main(String[] args) { + int n; + Scanner sc=new Scanner(System.in); + n=sc.nextInt(); + int a[]=new int[n]; + for(int i=0;i> tm) + { + if(root==null) return; + if(tm.containsKey(x)) + { + tm.get(x).add(new Pair(root,y)); + } + else + { + ArrayList al=new ArrayList<>(); + al.add(new Pair(root, y)); + tm.put(x,al); + } + dfs(root.left,x-1,y+1,tm); + dfs(root.right,x+1,y+1,tm); + } + ArrayList> vertical(Node root) + { + TreeMap> tm=new TreeMap<>(); + dfs(root, 0, 0, tm); + ArrayList> res=new ArrayList<>(); + for(Map.Entry> m:tm.entrySet()) + { + ArrayList temp=m.getValue(); + Collections.sort(temp,new Comparator() { + public int compare(Pair p1,Pair p2) + { + int k=Integer.compare(p1.y,p2.y); //First sort according to the height + return (k==0)?Integer.compare(p1.node.data,p2.node.data):k; //If height is equal then sort according to the node value + } + }); + ArrayList temp1=new ArrayList<>(); + for(Pair i:temp) + { + temp1.add(i.node.data); + } + res.add(temp1); + } + return res; + } +} +class abc +{ + public static void main(String[] args) { + Node root=new Node(1); + root.left=new Node(2); + root.left.left=new Node(4); + root.left.right=new Node(6); + root.right=new Node(3); + root.right.left=new Node(5); + root.right.right=new Node(7); + ArrayList> al=new Tree().vertical(root); + System.out.println(al); + } +} \ No newline at end of file