Array in ascending order

Problem Description

Given an unsorted array of integers arr, implement a function that returns the array sorted in ascending order, without using the built-in .sort() method (or any other library/utility sort).

Examples

Example 1

Input: arr = [5, 3, 1, 4, 2]

Output: [1, 2, 3, 4, 5]

Valid: true (all elements present, ascending order, .sort() not used)

Example 2

Input: arr = [5, 5, 5, 5]

Output: [5, 5, 5, 5]

Valid: true (duplicates preserved, already sorted)

Example 3

Input: arr = []

Output: []

Valid: true (empty array handled, no crash)

SystemVerilog

Code Editor Access

Log in to write, run and submit your solution to this interview question. It's free.

Output

Output goes here...