Skip to content

Comments

Working solution#1855

Open
avcode3 wants to merge 1 commit intosuper30admin:masterfrom
avcode3:master
Open

Working solution#1855
avcode3 wants to merge 1 commit intosuper30admin:masterfrom
avcode3:master

Conversation

@avcode3
Copy link

@avcode3 avcode3 commented Feb 22, 2026

No description provided.

@super30admin
Copy link
Owner

Your solution for the "Arrange Colors" problem is well-implemented and efficient. You correctly used the three-pointer approach (Dutch National Flag algorithm) to sort the array in one pass with constant space. The code is clean and easy to understand.

One minor point: in the condition for swapping 0, you swap and then increment both start_ptr and mid_ptr. This is correct because the element that was at start_ptr (which you swap with) must be a 1 (since all 0s have been moved to the left and all 2s to the right), so after swapping you can safely move mid_ptr forward. Similarly, when you see a 2, you swap with end_ptr and decrement end_ptr without moving mid_ptr because the element swapped from the end might be 0, 1, or 2 and needs to be rechecked.

Your solution passes all the test cases and meets the problem constraints. Well done!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants