a of size n distinct elements, sort the array in ascending order using the Bubble Sort algorithmnumSwaps is the number of swaps that took place.firstElement is the first element in the sorted array.lastElement is the last element in the sorted array.n, the number of elements in array aa[0],a[1],...,a[n-1]2 <= n <= 6001 <= a[i] <= 2 x 10^6, where 0 <= i < n1
2
3
4
5
6
7
8
9
10
11
12
13
14
#!/bin/python3
import math
import os
import random
import re
import sys
if __name__ == '__main__':
n = int(input().strip())
a = list(map(int, input().rstrip().split()))
# Write your code here
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#!/bin/python3
import math
import os
import random
import re
import sys
if __name__ == '__main__':
n = int(input().strip())
a = list(map(int, input().rstrip().split()))
# Write your code here
iteration_count = 0
for i in range(n):
for idx in range(n - i - 1):
if a[idx] > a[idx+1]:
a[idx], a[idx+1] = a[idx+1], a[idx]
iteration_count += 1
print("Array is sorted in {0} swaps.".format(iteration_count))
print("First Element:",a[0])
print("Last Element:",a[-1])