You are given a 0-indexed integer array nums and an integer pivot. Rearrange nums such that the following conditions are satisfied:


	Every element less than pivot appears before every element greater than pivot.
	Every element equal to pivot appears in between the elements less than and greater than pivot.
	The relative order of the elements less than pivot and the elements greater than pivot is maintained.
	
		More formally, consider every pi, pj where pi is the new position of the ith element and pj is the new position of the jth element. For elements less than pivot, if i &lt; j and nums[i] &lt; pivot and nums[j] &lt; pivot, then pi &lt; pj. Similarly for elements greater than pivot, if i &lt; j and nums[i] &gt; pivot and nums[j] &gt; pivot, then pi &lt; pj.
	
	


Return nums after the rearrangement.

&nbsp;
Example 1:

Input: nums = [9,12,5,10,14,3,10], pivot = 10
Output: [9,5,3,10,10,12,14]
Explanation: 
The elements 9, 5, and 3 are less than the pivot so they are on the left side of the array.
The elements 12 and 14 are greater than the pivot so they are on the right side of the array.
The relative ordering of the elements less than and greater than pivot is also maintained. [9, 5, 3] and [12, 14] are the respective orderings.


Example 2:

Input: nums = [-3,4,3,2], pivot = 2
Output: [-3,2,4,3]
Explanation: 
The element -3 is less than the pivot so it is on the left side of the array.
The elements 4 and 3 are greater than the pivot so they are on the right side of the array.
The relative ordering of the elements less than and greater than pivot is also maintained. [-3] and [4, 3] are the respective orderings.


&nbsp;
Constraints:


	1 &lt;= nums.length &lt;= 105
	-106 &lt;= nums[i] &lt;= 106
	pivot equals to an element of nums.


class Solution:
    def pivotArray(self, nums: List[int], pivot: int) -> List[int]:
        left=[]
        mid=[]
        right=[]
        for i in nums:
            if(i<pivot):
                left.append(i)
            elif(i==pivot):
                mid.append(i)
            else:
                right.append(i)
        return left+mid+right
// Time complexity = 2n = O(n)
// Space complexity = O(1), or O(n) if the result array is including in the complexity analysis.

class Solution {
    public int[] pivotArray(int[] nums, int pivot) {
        int[] result = new int[nums.length];
        int left = 0, right = nums.length - 1;

        for(int i = 0; i < nums.length; i++) {
            if(nums[i] < pivot) {
                result[left++] = nums[i];
            }
            if(nums[nums.length - 1 - i] > pivot) {
                result[right--] = nums[nums.length - 1 - i];
            }
        }

        while(left <= right) {
            result[left++] = pivot;
            result[right--] = pivot;
        }

        return result;
    }
}
class Solution {
public:
    vector<int> pivotArray(vector<int>& nums, int pivot) {
        int i = 0;
        vector<int> res;
        int cnt = count(nums.begin(), nums.end(), pivot);
        while(--cnt >= 0) {
            res.push_back(pivot);
        }
        for(int k = 0; k < nums.size(); k++) {
            if(nums[k] < pivot) {
                res.insert(res.begin() + i, nums[k]);
                i++;
            } else if(nums[k] > pivot) {
                res.push_back(nums[k]);
            } else
                continue;
        }
        return res;
    }
};
/**
 * @param {number[]} nums
 * @param {number} pivot
 * @return {number[]}
 */
var pivotArray = function(nums, pivot) {

    let n=nums.length;

    //first Solution with 3 separet Array
    let lessPivot=[]
    let equalPivot=[]
    let bigerPivot=[]

    for(let i=0;i<n;i++){
        if(nums[i]<pivot)lessPivot.push(nums[i])
        else if(nums[i]===pivot)equalPivot.push(nums[i])
        else bigerPivot.push(nums[i])

    }
    return lessPivot.concat(equalPivot.concat(bigerPivot))

    //second Solution with one Array

    let result=[]
    for(let num of nums){
        if(num<pivot)result.push(num)
    }

    for(let num of nums){
        if(num===pivot)result.push(num)
    }
    for(let num of nums){
        if(num>pivot)result.push(num)
    }
    return result
};
Partition Array According to Given Pivot