Array - 52: Segregate Odd & Even Numbers in given Array

Опубликовано: 28 Сентябрь 2024
на канале: Coding Simplified
39,890
407

Source Code: https://thecodingsimplified.com/segre...
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
   / 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/codingsimplif...

★☆★ Send us mail at: ★☆★
Email: [email protected]