BackmediumSorting and Partitioning

Three-Way Array Partitioning Solution

Problem Statement

Given an array of integers and two bounds, low and high, partition the array into three segments. The first segment should contain all elements less than low, the second segment should contain all elements equal to or greater than low but less than or equal to high, and the third segment should contain all elements greater than high.

Example 1
Input
{"array":[729146853],"low":4,"high":6}
Output
[123465789]

Explanation: The elements less than 4 are 1, 2, and 3. The elements greater than or equal to 4 but less than or equal to 6 are 4, 6, and 5. The elements greater than 6 are 7, 8, and 9.

Example 2
Input
{"array":[102030405060],"low":35,"high":45}
Output
[102030405060]

Explanation: The elements less than 35 are 10, 20, and 30. The elements greater than or equal to 35 but less than or equal to 45 are 40. The elements greater than 45 are 50 and 60.

Constraints

  • The array will contain at least 1 element and at most 10000 elements.
  • All elements in the array will be integers between 1 and 10000.
  • The bounds low and high will be integers between 1 and 10000.

More Sorting and Partitioning Problems

View all problems →
Live Compiler
Loading...
Test Cases & Output
🔒 Sign up to run your code

🚀 Practice this problem

Run code, get AI hints & track streak

Sign Up Free