Rearrange the elements of an array of integers such that all even numbers come before all odd numbers. This problem tests understanding of array manipulation and sorting concepts.
Given an array of integers, rearrange the array in-place such that all even numbers appear at the beginning of the array, followed by all odd numbers. The relative order of even numbers and odd numbers does not matter.
Imagine you have a deck of cards and need to separate the red cards from the black cards. A brute-force approach would be to create two new decks, one for red and one for black, going through the original deck one card at a time. This requires extra space proportional to the input size and takes linear time to iterate through the array.
Work through this problem with AI coaching and get real-time feedback
Practice This Problem