A kanban board sorts cards by estimate with quick sort, and you are writing its partition step. It works on nums in place, exactly like this:
pivot = nums[n - 1], and store starts at 0.j from 0 to n - 2: if nums[j] < pivot, swap nums[store] and nums[j], then add 1 to store.nums[store] and nums[n - 1], which puts the pivot at index store.Write partitionLast(nums) that changes nums in place as described. The tests check nums afterwards. An empty list stays empty.
Input: nums = [7,2,9,4,3,8,5] Output: [2,4,3,5,9,8,7]
2, 4, and 3 are smaller than the pivot 5 and move to the front in that order; 5 lands at index 3.
Input: nums = [1,2,3] Output: [1,2,3]
Both items are smaller than 3, and each swaps with itself.
0 <= nums.length <= 10^5-10^6 <= nums[i] <= 10^6Run tries your code on the examples. Submit runs every test, including hidden edge cases and big inputs that check your code is fast enough, and solves the problem when they all pass.
Ctrl + Enter runs, Ctrl + Shift + Enter submits (⌘ on a Mac).
I'm here to help with #197 Partition Around the Last Card. 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.