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.
Java, using 3 Sets (x planes, y planes, and z planes) and Long keys using 1024 states (0xff) for x, y, and z values.
importjava.io.*;importjava.math.*;importjava.security.*;importjava.text.*;importjava.util.*;importjava.util.concurrent.*;importjava.util.function.*;importjava.util.regex.*;importjava.util.stream.*;importstaticjava.util.stream.Collectors.joining;importstaticjava.util.stream.Collectors.toList;classResult{/* * Complete the 'surfaceArea' function below. * * The function is expected to return an INTEGER. * The function accepts 2D_INTEGER_ARRAY A as parameter. */publicstaticLong[]tmp;publicstaticLongxf=0xffffffl;publicstaticLongyf=0xffffl;publicstaticLongzf=0xffl;publicstaticvoidminiproc(Longk,Set<Long>s){if(s.contains(k)){s.remove(k);}else{s.add(k);}}publicstaticvoidproc(intx,inty,intz,Set<Long>xsides,Set<Long>ysides,Set<Long>zsides){Longroot=(x+0)*xf+(y+0)*yf+(z+0)*zf;Longright=(x+1)*xf+(y+0)*yf+(z+0)*zf;Longback=(x+0)*xf+(y+1)*yf+(z+0)*zf;Longtop=(x+0)*xf+(y+0)*yf+(z+1)*zf;miniproc(root,xsides);miniproc(root,ysides);miniproc(root,zsides);miniproc(right,xsides);miniproc(back,ysides);miniproc(top,zsides);}publicstaticintcalcsize(Set<Long>a,Set<Long>b,Set<Long>c){returna.size()+b.size()+c.size();}publicstaticintsurfaceArea(List<List<Integer>>A){// Write your code heretmp=newLong[6];Set<Long>xsides=newHashSet<>();Set<Long>ysides=newHashSet<>();Set<Long>zsides=newHashSet<>();for(inty=0;y<A.size();y++){List<Integer>parts=A.get(y);for(intx=0;x<parts.size();x++){inth=parts.get(x);for(intz=0;z<h;z++){proc(x,y,z,xsides,ysides,zsides);}}}returnxsides.size()+ysides.size()+zsides.size();}}publicclassSolution{publicstaticvoidmain(String[]args)throwsIOException{BufferedReaderbufferedReader=newBufferedReader(newInputStreamReader(System.in));BufferedWriterbufferedWriter=newBufferedWriter(newFileWriter(System.getenv("OUTPUT_PATH")));String[]firstMultipleInput=bufferedReader.readLine().replaceAll("\\s+$","").split(" ");intH=Integer.parseInt(firstMultipleInput[0]);intW=Integer.parseInt(firstMultipleInput[1]);List<List<Integer>>A=newArrayList<>();IntStream.range(0,H).forEach(i->{try{A.add(Stream.of(bufferedReader.readLine().replaceAll("\\s+$","").split(" ")).map(Integer::parseInt).collect(toList()));}catch(IOExceptionex){thrownewRuntimeException(ex);}});intresult=Result.surfaceArea(A);bufferedWriter.write(String.valueOf(result));bufferedWriter.newLine();bufferedReader.close();bufferedWriter.close();}}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
3D Surface Area
You are viewing a single comment's thread. Return to all comments →
Java, using 3 Sets (x planes, y planes, and z planes) and Long keys using 1024 states (0xff) for x, y, and z values.