FastPrepStable Odd-First Partition

Stable Odd-First Partition

Bloomberg LP logoBloomberg LP● EasyNEW GRADONSITE INTERVIEW
Learn

Problem statement

Return a new array containing every odd value from nums first, followed by every even value. Preserve the relative order within both groups.

Negative integers use ordinary divisibility by 2; for example -3 is odd.

Function

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

Examples

Example 1

nums = [2,3,4,1,6,5]return = [3,1,5,2,4,6]

Both the odd and even subsequences retain their input order.

Constraints

  • 0 <= nums.length <= 10^5.

More Bloomberg LP problems

See Bloomberg LP hiring insights
public int[] stableOddFirst(int[] nums) {
  // Write your code here.
}
nums[2,3,4,1,6,5]
expected[3,1,5,2,4,6]
Checking account…