Back to Browse

Sort Colors

2 views
May 11, 2026
5:18

In this video, I solved the LeetCode problem "Sort Colors" using the Dutch National Flag Algorithm. Problem: Given an array nums containing only: * 0s * 1s * 2s Sort the array in-place without using any built-in sorting function. Approach: We use three pointers: * low * mid * high Steps: * If nums[mid] is 0: * Swap with low * Move low and mid forward * If nums[mid] is 1: * Move mid forward * If nums[mid] is 2: * Swap with high * Move high backward This efficiently sorts the array in a single traversal. Time Complexity: O(n) Space Complexity: O(1) GitHub Link: https://github.com/Kumar-Aditya-DEV/Leetcode-Questions LeetCode Profile: https://leetcode.com/u/Aditya-Kumar-DEVP/ LinkedIn: https://www.linkedin.com/in/aditya-kumar-060ba6376/ Notes: * Uses Dutch National Flag Algorithm * Important two-pointer problem * In-place sorting approach * Frequently asked in coding interviews Language: C++ If this helped you, Like, Share and Subscribe for more coding content. #leetcode #cpp #dsa #coding #sorting #twopointers

Download

0 formats

No download links available.

Sort Colors | NatokHD