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.
publicstaticintrunningTime(List<Integer>arr){intcounter=0;//convert arraylist arr to array Integer[]array=newInteger[arr.size()];arr.toArray(array);//sorting the array for(inti=1;i<array.length;i++){inta=array[i];intj=i-1;while(j>=0&&array[j]>a){array[j+1]=array[j];//add value to counter in each iterationcounter=counter+1;j--;}array[j+1]=a;}returncounter;}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Running Time of Algorithms
You are viewing a single comment's thread. Return to all comments →
Here is my solution with Java 8: