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

preview_player
Показать описание
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:

Java Plus DSA Placement Course Playlist:

Java Plus DSA Sheet:

Notes:

Telegram Link:

Ultimate Recursion Series Playlist:

Samsung Interview Experience:

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)

imPriyansh
Автор

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

NishantPandat-lq
Автор

For [1, 0, 2] this approach isn't working

HmnTiyy
Автор

first view bhaiya. Thanks for uploading, 13K

PiyushSharma-weyd
Автор

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++;
}
}
}

nailshka
Автор

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

DevanshGupta-iorl
Автор

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

anandkumarnitrourkela
Автор

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

dibbodas
visit shbcf.ru