Selection Sort

Given an integer array nums, sort it in ascending order using selection sort and return the array. Selection sort grows a sorted prefix. On each pass, find…

Given an integer array `nums`, sort it in ascending order using selection sort and return the array. Selection sort grows a sorted prefix. On each pass, find the smallest value in the remaining suffix and swap it into the first unsorted position.

- `1 <= nums.length <= 10^3` - `-10^6 <= nums[i] <= 10^6` - Values may repeat. - Do not use a built-in sorting function.

Example 1: input nums = [64,25,12,22,11]; output [11,12,22,25,64]. Each pass selects the minimum from the unsorted suffix and places it next.

Example 2: input nums = [3,3,3]; output [3,3,3]. Each first unsorted value is already a minimum, so no swap changes the array.

Category: Sorting. Topic: sorting-searching. Difficulty: Easy. Patterns: linear-scan, sorting.