A sorting visualizer records every swap it animates. It runs selection sort ascending: for each position i from 0 to n - 2, it finds the smallest item in nums[i..n-1] (the leftmost one if several are equally small) and swaps it into position i. When the smallest item is already at i, no swap happens.
Write selectionSwaps(nums) that returns the list of swaps as pairs [i, minIndex], in the order they happen.
Input: nums = [29,10,14,37,13] Output: [[0,1],[1,4],[3,4]]
10 moves to 0, 13 to 1; 14 is already in place; then 29 moves to 3.
Input: nums = [1,2,3] Output: []
Every item is already the smallest of what remains.
0 <= nums.length <= 1000-10^6 <= nums[i] <= 10^6Run tries your code on the examples. Submit runs every test, including hidden edge cases, and solves the problem when they all pass.
Ctrl + Enter runs, Ctrl + Shift + Enter submits (⌘ on a Mac).
I'm here to help with #186 Selection Sort Swap Log. I give hints, never the solution, so you get to solve it yourself. Ask for a hint, select code to ask about it, or press Ask Tuto why on a failing test.
Your first 3 answers need no account. for free to keep asking.