75. Sort Colors | partition sorting | leetcode daily challenge | DSA | Hindi

Поділитися
Вставка
  • Опубліковано 27 сер 2024
  • Problem Name:
    75. Sort Colors
    Problem Statement:
    Given an array nums with n objects colored red, white, or blue, sort them in-place so that objects of the same color are adjacent, with the colors in the order red, white, and blue.
    We will use the integers 0, 1, and 2 to represent the color red, white, and blue, respectively.
    You must solve this problem without using the library's sort function.
    Problem link:
    leetcode.com/p...
    Java Plus DSA Placement Course Playlist:
    • Java and DSA Course Pl...
    Java Plus DSA Sheet:
    docs.google.co...
    Notes:
    github.com/Tiw...
    Telegram Link:
    shashwattiwari...
    Ultimate Recursion Series Playlist:
    • Recursion and Backtrac...
    Instagram Handle: (@shashwat_tiwari_st)
    shashwattiwari...
    Samsung Interview Experience:
    • I cracked Samsung | SR...
    Company Tags:
    Facebook | Amazon | Microsoft | Netflix | Google | LinkedIn | Pega Systems | VMware | Adobe | Samsung
    Timestamp:
    0:00 - Introduction
    #ShashwatTiwari #coding​​ #problemsolving​

КОМЕНТАРІ • 21

  • @priyanshkumar_iitd
    @priyanshkumar_iitd 2 місяці тому +1

    Thank you bhaiya !! 3 pointer approach !! new concept to sort in O(N)

  • @RohitKumar-dz8dh
    @RohitKumar-dz8dh 2 місяці тому +1

    Thanks 😊

  • @anushkaap
    @anushkaap 2 місяці тому +3

    Hello Sir, how is this approach i wrote on myself??
    class Solution {
    public void sortColors(int[] nums) {
    int w = 0, r = 0, b = 0;
    for(int num: nums) {
    if(num == 0) r++;
    else if(num == 1) w++;
    else b++;
    }
    int i = 0;
    while(r > 0) {
    nums[i] = 0;
    r--;
    i++;
    }
    while(w > 0) {
    nums[i] = 1;
    w--;
    i++;
    }
    while(b > 0) {
    nums[i] = 2;
    b--;
    i++;
    }
    }
    }

    • @shashwat_tiwari_st
      @shashwat_tiwari_st  2 місяці тому +5

      Good work 👏 you used counting sort without extra space. This solution meets all requirement, but it is not single pass solution, so it's not the most optimal one. TC will be same. But Looping is done multiple times.

    • @anushkaap
      @anushkaap 2 місяці тому +1

      @@shashwat_tiwari_st Thanks sir, I'll keep it in mind.

  • @PiyushSharma-we8yd
    @PiyushSharma-we8yd 2 місяці тому

    first view bhaiya. Thanks for uploading, 13K soooooonnn!!!!!

  • @karanchauke
    @karanchauke 2 місяці тому +2

    I think Flipkart Company 😂😂 Bhaiya

  • @user-oi5ls4rs5g
    @user-oi5ls4rs5g 2 місяці тому

    sir tree series k baad ...new lecture kb tak ayenge plz reply

  • @DevanshGupta-io7rl
    @DevanshGupta-io7rl 2 місяці тому

    sort stl laga k solve kr diya kya samaj muje accept krega ??

  • @anandkumarnitrourkela7404
    @anandkumarnitrourkela7404 2 місяці тому +1

    Bhaiya preparing for placements. struggling with graphs and dp what to do? Please guide

  • @Mrsainiworld
    @Mrsainiworld 2 місяці тому

    I think Twitter😅😅😅😅

  • @pushanmukhopadhyay3379
    @pushanmukhopadhyay3379 2 місяці тому +1

    Dutch flag algo

  • @DanishAli-ip2sj
    @DanishAli-ip2sj 2 місяці тому

    Waise ye qn medium lebel ka ni lga

  • @dibbodas4116
    @dibbodas4116 2 місяці тому

    sir how is the approach?
    class Solution {
    public:
    void sortColors(vector& nums) {
    int z = 0, o = 0, t = 0;
    for(int i=0;i0)
    {
    nums[i] = 1;
    o--;
    }
    else
    {
    nums[i] = 2;
    t--;
    }
    }
    }
    };

    • @shashwat_tiwari_st
      @shashwat_tiwari_st  2 місяці тому +1

      Badhiya hai. Counting sort without space, but multiple passes hai. Solution acha hai but most optimal nhi hai because of multiple loops (passes.) But good logic 👏💯

    • @dibbodas4116
      @dibbodas4116 2 місяці тому

      @@shashwat_tiwari_st yes bhaiya apka solution dekhne thora dikkat hua samajne me

  • @robinofautumn99
    @robinofautumn99 2 місяці тому

    long live yahoo🤣🤣