FastPrepPartition and Group Values by Parity

Partition and Group Values by Parity

EPAM logoEPAM● EasyFULLTIMEPHONE SCREEN
Learn

Problem statement

Given an integer array nums, return two groups: all even values in their original order, followed by all odd values in their original order.

The result must always contain exactly two rows. Either row may be empty.

Function

partitionByParity(nums: int[]) → int[][]

Examples

Example 1

nums = [3,2,4,1,0]return = [[2,4,0],[3,1]]

The first row contains stable evens and the second contains stable odds.

Example 2

nums = [2,4]return = [[2,4],[]]

The odd group is empty.

Constraints

  • 0 <= nums.length <= 100000.
  • -10^9 <= nums[i] <= 10^9.

Source note: Author-written prompt excerpt retained for source fidelity.

More EPAM problems

See EPAM hiring insights
public int[][] partitionByParity(int[] nums) {
    // Write your code here.
}
nums[3,2,4,1,0]
expected[[2,4,0],[3,1]]
Checking account…