Source Code: https://thecodingsimplified.com/segregate-even-odd-numbers-in-given-array/
Solution
- We'll take 2 variable, left & right
- Left = 0 & right = arr.length - 1
- Now we'll start from left & keep on increasing left as far as it's even value as our target is to place even values at first
- Similarly, we'll start from right & keep on decreasing right as far as it's odd value as our target is to place odd values in second part
- Now we swap values
- We do until left is lesser than right
Time Complexity: O(n), where n is elements of array
Space Complexity: O(1)
For more info, please see the video.
CHECK OUT CODING SIMPLIFIED
https://www.youtube.com/codingsimplified
★☆★ VIEW THE BLOG POST: ★☆★
http://thecodingsimplified.com
I started my YouTube channel, Coding Simplified, during Dec of 2015.
Since then, I've published over 500+ videos.
★☆★ SUBSCRIBE TO ME ON YOUTUBE: ★☆★
https://www.youtube.com/codingsimplified?sub_confirmation=1
★☆★ Send us mail at: ★☆★
Email: [email protected]