Input: arr[] = [5, 13, 6, 9, 12, 11, 8]
Output: [5, 6, 8, 13, 9, 12, 11]
Explanation: All elements smaller than pivot element [5, 6] were arranged before it and elements larger than pivot [13, 9, 12, 11] were arranged after it.
Input: arr[] = [4, 10, 9, 8, 16, 19, 9]
Output: [4, 9, 8, 9, 10, 16, 19]
Explanation: All elements smaller than or equal to pivot element [4, 9, 8] were arranged before it and elements larger than pivot [10, 16, 19] were arranged after it.
A simple approach to partition an array is to create a new temporary array which will store the rearranged elements. In this approach, we first iterate over the original array and add all elements that are smaller than or equal to the pivot to the temporary array. Then, we add the pivot element to the temporary array. Finally, we fill the remaining part of the temporary array with elements that are greater than the pivot.
This ensures that the smaller elements come before the pivot, and the larger elements come after it. Now, copy the elements from the temporary array back to the original array.