Tap here to switch tabs
Problem
Submissions

Problem: Partition Array According to Given Pivot

med
30 min
Try to solve the Partition Array According to Given Pivot problem.

Statement

Given an 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 pivot and the elements greater than pivot.

  • The relative order of elements smaller than pivot is preserved.

  • The relative order of elements greater than pivot is preserved.

Return the rearranged array.

Constraints:

  • 1≤1 \leq nums.length ≤105\leq 10^5

  • −106≤-10^6 \leq nums[i] ≤106\leq 10^6

  • pivot equals an element of nums.

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Partition Array According to Given Pivot

med
30 min
Try to solve the Partition Array According to Given Pivot problem.

Statement

Given an 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 pivot and the elements greater than pivot.

  • The relative order of elements smaller than pivot is preserved.

  • The relative order of elements greater than pivot is preserved.

Return the rearranged array.

Constraints:

  • 1≤1 \leq nums.length ≤105\leq 10^5

  • −106≤-10^6 \leq nums[i] ≤106\leq 10^6

  • pivot equals an element of nums.