DevHireLab
TutorialsBootcamp
Problems
Code SimulatorAI InterviewSoonContact
DevHireLab
TutorialsBootcamp
Problems
Code SimulatorAI InterviewSoonContact
Back to Arena
easy
Two Pointer

Sort Array By Parity

**Problem Statement:** Given the required input arguments, write an efficient algorithm to solve the **Sort Array By Parity** problem. Implement the required logic as specified by standard definitions for this classic algorithmic challenge. **Hint / Expected Approach:** Two-pointer partition (evens left, odds right) **Edge Cases to Consider:** - (1) All evens - (2) All odds - (3) Already partitioned

Examples

Example 1
Input: [3,1,2,4]
Output: Any arrangement where evens precede odds, e.g. [2,4,3,1]
Explanation: Basic mixed
Example 2
Input: [0]
Output: [0]
Explanation: Single even element
Example 3
Input: [1]
Output: [1]
Explanation: Single odd element

Constraints

  • ▪1 <= data.length <= 10^5
  • ▪Memory complexity must be O(1) or O(k)
  • ▪Ensure non-overlapping pointer access

Watch Out For Edge Cases

  • ▪All evens
  • ▪All odds
  • ▪Already partitioned
Frequently Asked At
AmazonMicrosoftAdobe