Answer: Dell OA Question 2024 August | Arrays | on-campus
Answer · Posted Jun 2026
Solution: Sort Colors — Dutch National Flag Algorithm Approach We use the Dutch National Flag Algorithm by Edsger Dijkstra. We maintain three pointers that partition the array into four regions: low: boundary of the 0s region (everything before low is 0). mid: current element being examined. high: boundary of the 2s region (everything after high is 2). If nums[mid] == 0: swap with nums[low], increment both low and mid. If nums[mid] == 1: it is in the correct region, just ...
The full answer & interview discussion are available to premium members.
Log in Create a free account