How do you sort an array consisting of 0s, 1s, and 2s without using built-in functions?

AnswerBot
2y

Sort an array of 0's, 1's, and 2's without using inbuilt functions.

  • Use three pointers to keep track of the last index of 0's, 1's, and 2's

  • Iterate through the array and swap elements based on their val...read more

Sharan. Medamoni
5mo
use the 3 pointers low = 0 , mid = 0 , high = arr.length-1 while(mid <= high){ if(mid == 0) swap(low , mid) else if (mid == 1) mid ++ else swap(high , mid); }
Help your peers!
Select
Add answer anonymously...
Ivanti Software Engineer Interview Questions
Stay ahead in your career. Get AmbitionBox app
play-icon
play-icon
qr-code
Trusted by over 1.5 Crore job seekers to find their right fit company
80 L+

Reviews

10L+

Interviews

4 Cr+

Salaries

1.5 Cr+

Users

Contribute to help millions

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2025 Info Edge (India) Ltd.

Follow Us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter
Profile Image
Hello, Guest
AmbitionBox Employee Choice Awards 2025
Winners announced!
awards-icon
Contribute to help millions!
Write a review
Write a review
Share interview
Share interview
Contribute salary
Contribute salary
Add office photos
Add office photos
Add office benefits
Add office benefits