Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Partition Odd and Even

EasyPython00:00
Practice interviewer
In session
5 left
00:00

Your question is Partition Odd and Even. Start with the requirements on the right.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.

Problem

Rearrange an array such that all odd numbers are on the left and all even numbers are on the right.

Implement def partition_odd_even(nums):, modifying the input list in place and returning it. The relative order of odd values and even values does not need to be preserved. An empty array is valid, and negative integers should be classified by parity.

Constraints

  • 0 <= nums.length <= 1000
  • -10^9 <= nums[i] <= 10^9
  • The input list must be modified in place
  • Any arrangement with all odd values before all even values is valid

Function Signature

def partition_odd_even(nums):
Your solutionPython 3
You need to log in / sign up to run or submit.
Run your code to see test output