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

แชร์
ฝัง
  • เผยแพร่เมื่อ 14 ต.ค. 2024
  • Source Code: thecodingsimpl...
    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: ★☆★
    thecodingsimpli...
    I started my TH-cam channel, Coding Simplified, during Dec of 2015.
    Since then, I've published over 500+ videos.
    ★☆★ SUBSCRIBE TO ME ON TH-cam: ★☆★
    www.youtube.co...
    ★☆★ Send us mail at: ★☆★
    Email: thecodingsimplified@gmail.com

ความคิดเห็น • 23

  • @karthikkoppala9664
    @karthikkoppala9664 ปีที่แล้ว +4

    Isn't the time complexity O(n^2)? Since we are using nested loop?

  • @shivamkumarjha3302
    @shivamkumarjha3302 3 ปีที่แล้ว +1

    Just Keep on. Your content is better than famous youtube channels. Thank you so much.

    • @CodingSimplified
      @CodingSimplified  3 ปีที่แล้ว

      Thanks for your nice feedback. Keep Watching.

  • @nikhilaggarwal9325
    @nikhilaggarwal9325 3 ปีที่แล้ว +4

    Your content is really good please keep on posting videos. I have learnt a lot from you. Thanks

    • @CodingSimplified
      @CodingSimplified  3 ปีที่แล้ว +1

      Thanks for your nice feedback. Keep Watching.

  • @sysybaba420
    @sysybaba420 ปีที่แล้ว +1

    what if had to maintain order(stability) of all even and odd numbers, then how would the code/login look like?

  • @yoshitamahajan353
    @yoshitamahajan353 3 ปีที่แล้ว +3

    Ur channel is so best!

    • @CodingSimplified
      @CodingSimplified  3 ปีที่แล้ว

      Thanks for your nice feedback. Keep Watching.

  • @something_different8968
    @something_different8968 ปีที่แล้ว

    so nice of you to make this simple. Thanks

  • @altheadelavegadewites941
    @altheadelavegadewites941 2 ปีที่แล้ว +2

    Your discussion are good, Would you please make a video on how to separate even and odd number from 1-100, Thankyou!!!

    • @CodingSimplified
      @CodingSimplified  2 ปีที่แล้ว

      Thanks for your feedback. Sure, I'll try to do. Noted your question.

  • @sakshitiwari4367
    @sakshitiwari4367 2 ปีที่แล้ว +2

    Why we swap the value can you please explain

  • @its_neel_ok
    @its_neel_ok ปีที่แล้ว

    how to sort this using in built sort function ----
    sort(a.begin(), a.end(), [](int x, int y) {
    return x % 2 < y % 2;
    });
    i got this code but didn't understand how can we manipulate sort function to our use?

  • @phuongdinh3769
    @phuongdinh3769 3 ปีที่แล้ว +2

    Hi I have 1 question, if you already put (left< right) in the big while loop, why do you still include it in the smaller while loop. Thanks

    • @itsabhinavbansal
      @itsabhinavbansal 3 ปีที่แล้ว +1

      There's no need to do that... 👍

  • @chandramoulieshn6070
    @chandramoulieshn6070 ปีที่แล้ว

    To make it effective, why don't we use "Lomuto’s Partition Scheme" --> lesser lines of code and provides the best understanding.

  • @a9ocalypse
    @a9ocalypse 2 ปีที่แล้ว +1

    Thanks a lot for this amazing explanation

  • @areegahmed3926
    @areegahmed3926 2 ปีที่แล้ว

    what if the odd numbers are more than the even?so the condition of right>left how will it work?

  • @NazmulAlom
    @NazmulAlom 2 ปีที่แล้ว

    Amazing session.

  • @prasenjitmitra8434
    @prasenjitmitra8434 3 ปีที่แล้ว +1

    Sir if we need to maintain the oder of numbers after segregation what we need to do

  • @surajgrandhi6742
    @surajgrandhi6742 2 ปีที่แล้ว

    what to do if they ask in the sorted form of even and odd

  • @codewithfaizu1520
    @codewithfaizu1520 2 ปีที่แล้ว

    suver