Practice Distribute Elements Into Two Arrays II
Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.
Distribute Elements Into Two Arrays II
Problem Statement
Treat nums as 1-indexed. Start arr1 with nums[1] and arr2 with nums[2], then process each remaining value in order. Define greaterCount(arr, value) as the number of entries in arr strictly greater than value. Append the new value to the array with the larger greaterCount; if tied, choose the shorter array; if still tied, choose arr1. Return arr1 followed by arr2, preserving order within each.
Source: Distribute Elements Into Two Arrays II on LeetCode. Use the original task for its coding environment and submissions.
Examples
# Example 1
nums = [2,1,3,3]
[2,3,1,3]
# Example 2
nums = [5,14,3,1,2]
[5,3,1,2,14]
# Example 3
nums = [3,3,3,3]
[3,3,3,3]
Constraints
Related LeetCode Problems
Practice more problems similar to Distribute Elements Into Two Arrays II.
Review your practice with PhantomCodeAI
After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.