A to-do app keeps its list sorted by insertion sort as items load: item i is lifted out and slides left past every earlier item that is strictly bigger, each step shifting that bigger item one place to the right.
Write shiftCounts(nums) that returns an array where entry i is how many shifts happen while inserting item i. Entry 0 is always 0.
Input: nums = [5,2,4,6,1,3] Output: [0,1,1,0,4,3]
1 slides past 6, 5, 4, 2 (4 shifts); 3 slides past 6, 5, 4 (3 shifts).
Input: nums = [1,2,3] Output: [0,0,0]
Each item is already bigger than everything before it.
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 #188 Insertion Shift Counts. 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.