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.
Standard imput is causings errors for 2 testcases..
classResult{/* * Complete the 'arraySplitting' function below. * * The function is expected to return an INTEGER. * The function accepts INTEGER_ARRAY arr as parameter. */publicstaticintarraySplitting(List<Integer>arr)throwsRuntimeException{int[]ps=newint[arr.size()];ps[0]=arr.get(0);for(inti=1;i<ps.length;i++){ps[i]=ps[i-1]+arr.get(i);}returnfun(0,ps.length-1,ps);}privatestaticintfun(intst,intend,int[]ps){if(st==end)return0;for(inti=0;i<end-st;i++){intfs=0,ss=0;if(st==0)fs=ps[st+i];elsefs=ps[st+i]-ps[st-1];ss=ps[end]-ps[st+i];if(ss==fs){returnMath.max(fun(st,st+i,ps),fun(st+i+1,end,ps))+1;}}return0;}}publicclassSolution{publicstaticvoidmain(String[]args)throwsIOException{Scannersc=newScanner(System.in);intt=sc.nextInt();for(inti=0;i<t;i++){intn=sc.nextInt();List<Integer>list=newArrayList<>();for(intj=0;j<n;j++){list.add(sc.nextInt());}System.out.println(Result.arraySplitting(list));}}}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Nikita and the Game
You are viewing a single comment's thread. Return to all comments →
Standard imput is causings errors for 2 testcases..