LeetCode 75. Sort Colors [Solution + Code Explained ]

  Рет қаралды 4,742

jayati tiwari

jayati tiwari

4 жыл бұрын

One of the most frequently asked coding interview questions on Arrays in companies like Google, Facebook, Amazon, LinkedIn, Microsoft, Uber, Apple, Adobe etc.
LeetCode 75. Sort Colors
Question : Given an array 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.
Here, we will use the integers 0, 1, and 2 to represent the color red, white, and blue respectively.
Note: You are not suppose to use the library's sort function for this problem.
Example:
Input: [2,0,2,1,1,0]
Output: [0,0,1,1,2,2]
Follow up:
A rather straight forward solution is a two-pass algorithm using counting sort.
First, iterate the array counting number of 0's, 1's, and 2's, then overwrite array with total number of 0's, then 1's and followed by 2's.
Could you come up with a one-pass algorithm using only constant space?
Connect with me on LinkedIn at: / jayati-tiwari

Пікірлер: 7
@prasadkatre
@prasadkatre 3 жыл бұрын
Hi Jayanti, where did you find the list of approaches? Can you please post the complete list of problem solving approaches it would be of great help.
@chintamalli695
@chintamalli695 3 жыл бұрын
Before watching the video, I took 30 mins to solve this problem but failed to write third variable i.e K. Thank a ton
@starlordopgaming9410
@starlordopgaming9410 4 жыл бұрын
Nice
@vaibhavgupta2
@vaibhavgupta2 4 жыл бұрын
Jayati it is really helpful!
@vamsinadh100
@vamsinadh100 4 жыл бұрын
MyApproach:codetoskill.blogspot.com/2020/06/sort-colors-leetcode-challenge-june-day.html
@ChanderVivekSingh
@ChanderVivekSingh 2 жыл бұрын
very easily understood from your dry run Thanks buddy..Also Thanks to this youtuber
@starlordopgaming9410
@starlordopgaming9410 4 жыл бұрын
Coding ka channel hai kya tumhara sirf
LeetCode 394. Decode String   [Solution + Code Explained ]
16:24
jayati tiwari
Рет қаралды 17 М.
Box jumping challenge, who stepped on the trap? #FunnyFamily #PartyGames
00:31
Family Games Media
Рет қаралды 19 МЛН
小蚂蚁被感动了!火影忍者 #佐助 #家庭
00:54
火影忍者一家
Рет қаралды 39 МЛН
LeetCode 312. Burst Balloons[ Algorithm + Code Explained]
18:31
jayati tiwari
Рет қаралды 8 М.
Sort Colors - Quicksort Partition - Leetcode 75 - Python
15:48
Sort colors | Leetcode #75
6:02
Techdose
Рет қаралды 84 М.
Quicksort In Python Explained (With Example And Code)
14:13
FelixTechTips
Рет қаралды 140 М.
LeetCode 85. Maximal Rectangle [ Solution + Code Explained]
16:28
jayati tiwari
Рет қаралды 12 М.
Leetcode | 198. House Robber | Medium | Java Solution [2 Methods]
17:16
Box jumping challenge, who stepped on the trap? #FunnyFamily #PartyGames
00:31
Family Games Media
Рет қаралды 19 МЛН