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.
defcountSwaps(a):count=0n=len(a)-1forpassesinrange(n):foriinrange(n-passes):ifa[i]>a[i+1]:a[i],a[i+1]=a[i+1],a[i]count+=1# print(a,passes-1)print(f"Array is sorted in {count}swaps.\nFirstElement:{a[0]}\nLastElement:{a[-1]}")
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Sorting: Bubble Sort
You are viewing a single comment's thread. Return to all comments →