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
Thank you bhaiya !! 3 pointer approach !! new concept to sort in O(N)
Thanks 😊
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++;
}
}
}
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.
@@shashwat_tiwari_st Thanks sir, I'll keep it in mind.
first view bhaiya. Thanks for uploading, 13K soooooonnn!!!!!
I think Flipkart Company 😂😂 Bhaiya
sir tree series k baad ...new lecture kb tak ayenge plz reply
sort stl laga k solve kr diya kya samaj muje accept krega ??
😂samaj kar lega pr tech community nhi karegi
Bhaiya preparing for placements. struggling with graphs and dp what to do? Please guide
Strike bhai op
I think Twitter😅😅😅😅
Dutch flag algo
Yes!
Waise ye qn medium lebel ka ni lga
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--;
}
}
}
};
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 👏💯
@@shashwat_tiwari_st yes bhaiya apka solution dekhne thora dikkat hua samajne me
long live yahoo🤣🤣