Running Time of Algorithms

  • + 0 comments

    **MY CPP EASY SOLUTION **

    int runningTime(vector<int> arr) {
        int shifts=0,n=arr.size();
        for(int i=0;i<n;i++){
            int temp=i;
            for(int j=i-1;j>=0;j--){
                if(arr[temp]<arr[j]){
                    swap(arr[temp],arr[j]);
                    shifts++;
                    temp=j;
                }
                else break;
            }
        }
        
        return shifts;
    }