Description
Submission
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<int> a(n); for(int a_i = 0; a_i < n; a_i++){ cin >> a[a_i]; } // Write Your Code Here int swaps = 0; for(int i = 0; i < n - 1; ++i) { for(int j = n - 1; j > i; --j) { if(a[j-1] > a[j]) { swap(a[j-1], a[j]); swaps++; } } } cout << "Array is sorted in " << swaps << " swaps.\n"; cout << "First Element: " << a[0] << endl; cout << "Last Element: " << a[n-1] << endl; return 0; }