Geeksforgeeks

Error

×

Leaderboard

Showing:

Handle | Score |
---|---|

@Ibrahim Nash | 5725 |

@blackshadows | 5685 |

@akhayrutdinov | 5111 |

@mb1973 | 4989 |

@Quandray | 4908 |

@saiujwal13083 | 4156 |

@sanjay05 | 3762 |

@marius_valentin_dragoi | 3511 |

@sushant_a | 3453 |

@KshamaGupta | 3318 |

@the_coder95 | 3302 |

Complete Leaderboard | |

Handle | Score |

@avaiesshaik782 | 782 |

@arpitsatnalika | 773 |

@tujhekya | 602 |

@prakharxyz | 597 |

@code_it_ | 591 |

@iamronak | 505 |

@imnm | 500 |

@pradeepkumarjad | 488 |

@satyam0460 | 481 |

@Rahul Jadhav 1 | 466 |

@sivanandh03 | 464 |

Complete Leaderboard |

Given an array of size N and a range [**a**, **b**]. The task is to partition the array around the range such that array is divided into three parts.

1) All elements smaller than **a** come first.

2) All elements in range **a** to **b** come next.

3) All elements greater than **b** appear in the end.

The individual elements of three sets can appear in any order. You are required to return the modified array.

**Example 1:**

**Input**:
N = 5
A[] = {1, 2, 3, 3, 4}
[a, b] = [1, 2]
**Output:** 1
**Explanation**: One possible arrangement is:
{1, 2, 3, 3, 4}. If you return a valid
arrangement, output will be 1.

**Example 2:**

**Input**: N = 3
A[] = {1, 2, 3}
[a, b] = [1, 3]
**Output**: 1
**Explanation: **One possible arrangement
is: {1, 2, 3}. If you return a valid
arrangement, output will be 1.

**Your Task: **

You dont need to read input or print anything. The task is to complete the function **threeWayPartition()** which takes the array[], a and b as input parameters and modifies the array in-place according to the given conditions.

**Note:** The generated output is 1 if you modify the given array successfully.

**Expected Time Complexity:** O(N)

**Expected Auxiliary Space:** O(1)

**Constraints:**

1 <= N <= 10^{6}

1 <= A[i] <= 10^{6}

Login to report an issue on this page.

We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?

Yes
Three way partitioning

...

Please choose 'ReadOnlyMode' if you needn't to 'Edit' the problem e.g. viewing OJ's solution, TestCase Files (TCFs), TimeLimit etc.