• + 0 comments

    Python Code:

    if __name__ == '__main__':
        n = int(input().strip())
    
        a = list(map(int, input().rstrip().split()))
        
        swap = 0
        for i in range(n):
            for j in range(i, n):
                if a[i]>a[j]:
                    a[i], a[j] = a[j], a[i]
                    swap+=1
                    
        print(f"Array is sorted in {swap} swaps.")
        print(f"First Element: {a[0]}")
        print(f"Last Element: {a[-1]}")