Selection Sort

Implement selectionSort

Given an array of integers, sort it in non-decreasing order using **Selection Sort** — repeatedly find the smallest value among what's left to place, and put it into its correct position. Unlike bubble sort or insertion sort, selection sort makes at most one swap per pass — it spends its time searching for the minimum rather than moving values around during the search. That makes the number of writes to the array very predictable (exactly n-1 swaps total), even though the number of comparisons is the same O(n²) as the other simple sorts.

Example 1:

Input: arr = [7,2,9,4,2,8]

Output: [2,2,4,7,8,9]

Example 2:

Input: arr = []

Output: []

Example 3:

Input: arr = [5]

Output: [5]

+ 5 hidden test cases run on Submit.

Constraints:

  • 0 ≤ arr.length ≤ 200
  • -1000 ≤ arr[i] ≤ 1000
  • Sort in non-decreasing order

arr =

[7, 2, 9, 4, 2, 8]