• + 0 comments
    public static int surfaceArea(List<List<Integer>> A) {
        // Write your code here
            int front = 0;int side1 = 0;int side2 = 0;int bttm = 0;int back = 0;int top = 0;
            int frontInt = 0;int sideInt = 0;//Internals
            //Side1 and Side2
            side1 = A.get(0).stream().mapToInt(Integer::intValue).sum();
            side2 = A.get(A.size()-1).stream().mapToInt(Integer::intValue).sum();
            int i = 0;
            for(List<Integer> list : A){
                int zeroCount = (int) list.stream().filter(n -> n == 0).count();
                front += list.get(0);//Only works if no empty space..i.e filled with 0 
                top += (list.size()-zeroCount);//Those with 0 height
                bttm = top;
                back += list.get(list.size()-1);
                //Calculate front and side internals
                if(i>0){
                    List<Integer> B = A.get(i-1);
                    int maxLength = Math.max(list.size(), B.size());
    
            sideInt += IntStream.range(0, maxLength)
                .map(h -> {
                    int a = h < list.size() ? list.get(h) : 0;
                    int b = h < B.size() ? B.get(h) : 0;
                    return Math.abs(a - b);
                })
                .sum();
                }
                frontInt += IntStream.range(1, list.size())
                .map(k -> Math.abs(list.get(k) - list.get(k - 1)))
                .sum();
                i++;
            }
            System.out.printf("front: %d,side1: %d,side2: %d,back: %d, top: %d, bttm: %d, sideInt: %d, frtInt: %d",front,side1,side2,back,top,bttm,sideInt,frontInt);
            return front+side1+side2+back+top+bttm+sideInt+frontInt;
        }