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.
importjava.io.*;importjava.util.*;importjava.text.*;importjava.math.*;importjava.util.regex.*;importjava.util.Collections.*;publicclassSolution{publicstaticvoidmain(String[]args){/* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */Scannersc=newScanner(System.in);intn,count=0,count1=0;n=sc.nextInt();int[]b=newint[n];Integer[]a=newInteger[n];int[]c=newint[n];HashMapmap=newHashMap();HashMapmap1=newHashMap();for(inti=0;i<n;i++){intnum=sc.nextInt();map.put(num,i);map1.put(num,i);a[i]=num;b[i]=num;c[i]=num;}Arrays.sort(a);for(inti=0;i<n;i++){if(a[i]!=b[i]){count++;inttemp=b[(int)map.get(a[i])];intx=b[(int)map.get(a[i])];b[(int)map.get(a[i])]=b[i];b[i]=temp;map.put(b[(int)map.get(a[i])],(int)map.get(b[i]));}}Arrays.sort(a,Collections.reverseOrder());for(inti=0;i<n;i++){if(a[i]!=c[i]){count1++;inttemp=c[(int)map1.get(a[i])];intx=c[(int)map1.get(a[i])];c[(int)map1.get(a[i])]=c[i];c[i]=temp;map.put(c[(int)map1.get(a[i])],(int)map1.get(b[i]));}}if(count1>count)System.out.println(count);elseSystem.out.println(count1);}}
Doesnt run for test case 2 3 and 9
Why???
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Lily's Homework
You are viewing a single comment's thread. Return to all comments →
Doesnt run for test case 2 3 and 9 Why???