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.
functionrunningTime($arr){// Write your code here$total=0;for($i=0;$i<count($arr)-1;$i++){$temp=0;for($j=$i+1;$j<count($arr);$j++){if($arr[$j]<$arr[$i]){$temp=$arr[$j];// delete array $arr[$j]unset($arr[$j]);// insert in front of arrayarray_splice($arr,$i,0,$temp);// count step$total=$total+($j-$i);// re-index array$arr=array_values($arr);}}}return$total;}
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's my PHP solution: