Skip to content

Practice Partition Array According to Given Pivot

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Medium#2161
LeetCode Problem

Partition Array According to Given Pivot

Problem Statement

Return nums reordered into three consecutive regions: values below pivot, values equal to pivot, and values above pivot. Preserve original relative order among below-pivot entries and among above-pivot entries.

Source: Partition Array According to Given Pivot on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
nums = [9,12,5,10,14,3,10], pivot = 10
Output
[9,5,3,10,10,12,14]

# Example 2

Input
nums = [-3,4,3,2], pivot = 2
Output
[-3,2,4,3]

Constraints

1 <= nums.length <= 10^5
-10^6 <= nums[i] <= 10^6
pivot equals to an element of nums.

Related LeetCode Problems

Practice more problems similar to Partition Array According to Given Pivot.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.