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.
  • Hackerrank Home
  • Prepare
    NEW
  • Certify
  • Compete
  • Career Fair
  • Hiring developers?
  1. Prepare
  2. Algorithms
  3. Sorting
  4. Running Time of Algorithms
  5. Discussions

Running Time of Algorithms

Problem
Submissions
Leaderboard
Discussions

    You are viewing a single comment's thread. Return to all comments →

  • zerotohero
    3 years ago+ 1 comment
    #python3
    def runningTime(arr):
        z=0
        if arr==sorted(arr):
            return (0)    
        else:
            for i in range(1,len(arr)):
                x=arr[i]
                for j in range(i):
                    if arr[j]>x:
                        (arr[i],arr[j])=(arr[j],arr[i])
                        z+=1
            
            return z
    
    6|
    Permalink
  • Blog
  • Scoring
  • Environment
  • FAQ
  • About Us
  • Support
  • Careers
  • Terms Of Service
  • Privacy Policy
  • Request a Feature