Given an array, arr[]. Sort the array using bubble sort algorithm. Input…
PYQ Accenture Hiring Assessment 2026
Given an array, arr[]. Sort the array using bubble sort algorithm.
Input format
The first line contains one integer n — the size of the array. The second line contains n space-separated integers arr[0], arr[1], …, arr[n−1].
Output format
Print the sorted values on a single line as [a, b, c, …] — the values in ascending order, separated by a comma and a single space, enclosed in square brackets.
For example, the first sample below is supplied on stdin as:
5
4 1 3 9 7and your program must print exactly:
[1, 3, 4, 7, 9]Examples :
Input: arr[] = [4, 1, 3, 9, 7]
Output: [1, 3, 4, 7, 9]
Explanation: After sorting, the array in ascending order of their values is [1, 3, 4, 7, 9].
Input: arr[] = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]
Output: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
Explanation: Sort the array in ascending order of their values.
Input: arr[] = [1, 2, 3, 4, 5]
Output: [1, 2, 3, 4, 5]
Explanation: An array that is already sorted should remain unchanged after applying bubble sort.
Constraints:
1 ≤ arr.size() ≤ 103
1 ≤ arr[i] ≤ 103
Attempted by 2 students.
Sign up free to check your answer
Sign up freeLoading lesson…

