0
Leetcode Problem 2161. Partition Array According to Given Pivot
2161. Partition Array According to Given Pivot
AI Mock Interview
Leetcode Solutions
Three-Pass Partitioning
Solution Idea
Algorithm Steps
Code Implementation
Complexity Analysis
Initialize three empty lists (or arrays) for elements less than, equal to, and greater than the pivot.
Iterate through the input array
nums
and for each element:
If it is less than
pivot
, add it to the 'less than' list.
If it is equal to
pivot
, add it to the 'equal to' list.
If it is greater than
pivot
, add it to the 'greater than' list.
Concatenate the three lists in the order of 'less than', 'equal to', and 'greater than' to form the rearranged array.
Return the rearranged array.
In-Place Two-Pointer Approach
Ask Question
Programming Language
Purpose:
General Question
Debug My Code
image/screenshot of info
(optional)
[+]
Full Screen
Loading...
Get Answer
Suggested Answer
Answer
Full Screen
Copy Answer Code
Loading...