Lomuto's partition takes the last element as the pivot and sweeps the rest from left to right, keeping a boundary i such that everything up to i is at most the pivot. Each small element found is swapped up to just past the boundary; at the end the pivot itself is swapped into place.
Write lomuto_partition(nums) which partitions the whole list in place and returns the pivot's final index. The order inside each side does not matter as long as it is the order this procedure produces.
Examples
Input: nums = [7, 2, 9, 1, 5]
Output: 2, and nums becomes [2, 1, 5, 7, 9]
Explanation: 2 and 1 are at most 5, so they move to the front; the pivot lands at index 2.
Input: nums = [4]
Output: 0, and nums is unchanged
Constraints
1 <= len(nums) <= 10**5,-10**9 <= nums[i] <= 10**9- Partition in place: do not build a new list.
- The tests call
partition_result(nums), which runs your function and returns the pair(index, nums).
Goals
- Rearrange a list around a pivot in a single left-to-right pass
- Keep one boundary index for 'everything before here is small'
- Finish by swapping the pivot into the gap the boundary leaves