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.
I did it in the same way but I include more code for constraints. My code passes 100% test cases too. I saw that you does not include code for constraints. It is weird that your code passes 100% test cases, may be the test cases not include the constraints validation. Well congratulations your code is great.
Let me share my code, any comment is welcome:
publicstaticvoidmain(String[]args){Scannerin=newScanner(System.in);ints=in.nextInt();intt=in.nextInt();inta=in.nextInt();intb=in.nextInt();intm=in.nextInt();intn=in.nextInt();int[]datas={s,t,a,b,m,n};intapples=0,oranges=0;for(intdata:datas){if((data<=1)&&(data>=Math.pow(10,5))){System.err.println("Data out of range.");System.exit(-1);}}if((a>s)&&(s>t)&&(t>b)){System.err.println("the data does not meet the requirements.");System.exit(-1);}int[]apple=newint[m];for(intapple_i=0;apple_i<m;apple_i++){apple[apple_i]=in.nextInt();if(apple[apple_i]>=Math.pow(-10,5)&&apple[apple_i]<=Math.pow(10,5)){if(((a+apple[apple_i])>=s)&&((a+apple[apple_i])<=t))apples++;}else{System.err.println("Apple: Distance out of the range."+apple[apple_i]);System.exit(-1);}}int[]orange=newint[n];for(intorange_i=0;orange_i<n;orange_i++){orange[orange_i]=in.nextInt();if(orange[orange_i]>=Math.pow(-10,5)&&orange[orange_i]<=Math.pow(10,5)){if(((b+orange[orange_i])>=s)&&((b+orange[orange_i])<=t))oranges++;}else{System.err.println("Orange: Distance out of the range."+orange[orange_i]);System.exit(-1);}}System.out.println(apples);System.out.println(oranges);}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Apple and Orange
You are viewing a single comment's thread. Return to all comments →
I did it in the same way but I include more code for constraints. My code passes 100% test cases too. I saw that you does not include code for constraints. It is weird that your code passes 100% test cases, may be the test cases not include the constraints validation. Well congratulations your code is great.
Let me share my code, any comment is welcome: