Sort Array By Parity
Sort Array By Parity
Given an integer array nums, rearrange the elements such that all even integers appear before all odd integers.
Return any array that satisfies this condition.
Example 1:
Input: nums = [3,1,2,4]
Output: [2,4,3,1]
Explanation: Other valid outputs include [4,2,3,1], [2,4,1,3], and [4,2,1,3].
Example 2:
Input: nums = [0]
Output: [0]
Constraints:
1 <= nums.length <= 50000 <= nums[i] <= 5000
Similar LeetCode problem: Sort Array By Parity
AI interview prep
Core dilemma
In-place modification versus creating a new array, and optimizing for minimal operations.
2 tradeoffs and 3 stress tests locked
Interview prep
Unlock the interviewer X-Ray rubric, tradeoff matrix, stress tests, clarifying questions, and key concepts.
Sort Array By Parity
Sort Array By Parity
Given an integer array nums, rearrange the elements such that all even integers appear before all odd integers.
Return any array that satisfies this condition.
Example 1:
Input: nums = [3,1,2,4]
Output: [2,4,3,1]
Explanation: Other valid outputs include [4,2,3,1], [2,4,1,3], and [4,2,1,3].
Example 2:
Input: nums = [0]
Output: [0]
Constraints:
1 <= nums.length <= 50000 <= nums[i] <= 5000
Similar LeetCode problem: Sort Array By Parity