• Courses
  • Tutorials
  • Jobs
  • Practice
  • Contests
April 07, 2022 |15.5K Views
Sort an array of 0s, 1s and 2s | SDE Sheet | Arrays
  Share  9 Likes
Description
Discussion

Sorting is one of the very famous operations we use in our day to day life. 

In this video we will see how we sort an array of 0s,1s and 2s in such a way that all 0s come first, then 1s and then 2s. 

Example: 

Input: {0, 1, 2, 0, 1, 2} 

Output: {0, 0, 1, 1, 2, 2} 

Check out the video to see how we implement this!! 

Next Video: https://www.geeksforgeeks.org/videos/reverse-array-in-groups-sde-sheet-arrays/ 

Practice Problem: https://practice.geeksforgeeks.org/problems/sort-an-array-of-0s-1s-and-2s4231/1 

Article: https://www.geeksforgeeks.org/sort-an-array-of-0s-1s-and-2s/ 

SDE Sheet: https://www.geeksforgeeks.org/sde-sheet-a-complete-guide-for-sde-preparation/

Read More