@@ -0,0 +1,1647 @@
+package com.problems.techiedelight;%0A%0Aimport javafx.util.Pair;%0A%0Aimport java.util.Comparator;%0Aimport java.util.PriorityQueue;%0A%0A/**%0A * Created by Maks on 5/10/2017.%0A * http://www.techiedelight.com/find-smallest-range-least-one-element-given-lists/%0A */%0Apublic class SmallestRangeInAllLists %7B%0A%0A    public Pair%3CInteger,Integer%3E solution1(Integer%5B%5D%5B%5D arr)%7B%0A        PriorityQueue%3CRange%3E pq=new PriorityQueue%3CRange%3E(comparator);%0A        int max=Integer.MIN_VALUE;%0A        int min=Integer.MAX_VALUE;%0A        int minRange=min;%0A        Pair%3CInteger,Integer%3E res=new Pair%3CInteger, Integer%3E(0, Integer.MAX_VALUE);%0A%0A        for(int i=0; i%3Carr.length; i++)%7B%0A            max=Math.max(max, arr%5Bi%5D%5B0%5D);%0A            pq.add(new Range(arr%5Bi%5D%5B0%5D,i,1));%0A        %7D%0A        for(;;)%7B%0A            min=pq.peek().data;%0A            int i=pq.peek().array;%0A            int j=pq.peek().idx;%0A%0A            pq.poll();%0A%0A            if(max-min%3Cres.getValue()-res.getKey())%7B%0A                res=new Pair%3CInteger, Integer%3E(max, max);%0A            %7D%0A            if(j==arr%5Bi%5D.length-1)%7B%0A                return  res;%0A            %7D%0A            pq.add(new Range(arr%5Bi%5D%5Bj+1%5D,i,j+1));%0A            max=Math.max(max, arr%5Bi%5D%5Bj+1%5D);%0A        %7D%0A    %7D%0A%0A    public  class Range%7B%0A        public final int data;%0A        public  final int array;%0A        public  final int idx;%0A%0A        public Range (int data,int array,int idx) %7B%0A            this.data=data;%0A            this.array=array;%0A            this.idx=idx;%0A        %7D%0A    %7D%0A%0A    public   Comparator%3CRange%3E comparator =new Comparator%3CRange%3E() %7B%0A        public int compare(Range o1, Range o2) %7B%0A            return  o1.data-o2.data;%0A        %7D%0A    %7D;%0A%0A%0A%7D%0A

Find smallest range with at-least one element from each of the given lists