Shell sort is built from gapped insertion passes. One pass with gap gap insertion-sorts each group of items that are gap apart: positions 0, gap, 2 × gap, ..., then 1, 1 + gap, ..., and so on, each group on its own.
Write gappedPass(nums, gap) that returns a new array after one such pass. Items in different groups never move relative to each other's positions.
Input: nums = [23,12,1,8,34,54,2,3], gap = 4 Output: [23,12,1,3,34,54,2,8]
The groups are (23, 34), (12, 54), (1, 2), and (8, 3). Only the last group is out of order.
Input: nums = [5,4,3,2,1], gap = 1 Output: [1,2,3,4,5]
Gap 1 is a normal insertion sort.
0 <= nums.length <= 10001 <= gap <= 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 #210 One Gapped Insertion Pass. 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.