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.
if__name__=='__main__':n=int(input().strip())a=list(map(int,input().rstrip().split()))swapy=0foriinrange(n):forjinrange(n-1):wartosc=int()if(a[j]>a[j+1]):wartosc=a[j]a[j]=a[j+1]a[j+1]=wartoscswapy+=1print("Array is sorted in "+str(swapy)+" swaps.")print("First Element: "+str(a[0]))print("Last Element: "+str(a[-1]))
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Day 20: Sorting
You are viewing a single comment's thread. Return to all comments →
**Python code: **