# Problem Statement
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 $p_i$, $p_j$ where $p_i$ is the new position of the $i^{th}$ element and $p_j$ is the new position of the $j^{th}$ element. If `i < j` and **both** elements are smaller (_or larger_) than `pivot`, then $p_i< p_j$.
Return `nums` _after the rearrangement._
## Constraints
- `1 <= nums.length <=` 10^5`
- `-10^6 <= nums[i] <=` 10^6`
- `pivot` equals to an element of `nums`.
# Solution
This can be done with less memory, but for the sake of simplicity I will use three lists. One to store the elements less than the pivot, one for the elements equal to the pivot, and one for the elements greater than the pivot. All that's left to do now is loop through `nums` and append each number to the list they belong to. Finally, we concatenate the three lists and return that as the answer.
```python
less, equal, greater = [], [], []
for num in nums:
if num < pivot: less.append(num)
if num == pivot: equal.append(num)
if num > pivot: greater.append(num)
return less + equal + greater
```
Time Complexity: O$(n)$ | Space Complexity: O$(n)$