Mid
From PDF
Coding
C# Coding Interview
Sort Array of 0s, 1s, and 2s (Dutch National Flag)?
Short answer: void SortColors(int[] nums) {
Example code
int low = 0, mid = 0, high = nums.Length - 1; while (mid <= high) {
if (nums[mid] == 0)
(nums[low++], nums[mid++]) = (nums[mid], nums[low]); else if (nums[mid] == 1) mid++; else (nums[mid], nums[high--]) = (nums[high], nums[mid]);
}
} Follow on: Explanation: Partition array into three parts in one pass using three pointers.
Real-world example (ShopNest)
In coding rounds, state complexity aloud, write a clear ShopNest-flavored example (orders, carts), then handle edge cases (empty list, null, overflow).
Say this in the interview
- Define — one clear sentence (the short answer above).
- Example — relate it to a project like ShopNest or your real work.
- Trade-off — when you would not use it.
Share this Q&A
Share preview image: https://www.toolliyo.com/images/toolliyo-logo.png