โ— LIVE
OpenAI releases GPT-5 APIIndia AI startup raises $120MBitcoin ETF hits record inflowsMeta Llama 4 benchmarks leakedOpenAI releases GPT-5 APIIndia AI startup raises $120MBitcoin ETF hits record inflowsMeta Llama 4 benchmarks leaked
๐Ÿ“… Mon, 23 Mar, 2026โœˆ๏ธ Telegram
AiFeed24

AI & Tech News

๐Ÿ”
โœˆ๏ธ Follow
๐Ÿ Home๐Ÿค–AI๐Ÿ’ปTech๐Ÿš€Startupsโ‚ฟCrypto๐Ÿ”’Security๐Ÿ‡ฎ๐Ÿ‡ณIndiaโ˜๏ธCloud๐Ÿ”ฅDeals
โœˆ๏ธ News Channel๐Ÿ›’ Deals Channel
CA 08 - Sort 0s, 1s, and 2s
โ˜๏ธCloud & DevOps

CA 08 - Sort 0s, 1s, and 2s

Home/Cloud & DevOps/CA 08 - Sort 0s, 1s, and 2s

Problem Statement: here Problem Understanding: Solution: arr = [0, 1, 2, 0, 1, 2] low = 0 mid = 0 high = len(arr) - 1 while mid <= high: if arr[mid] == 0: arr[low], arr[mid] = arr[mid], arr[low] low += 1 mid += 1 elif arr[mid] == 1: mid += 1 else: arr[mid], arr[high] = arr[high], arr[mid] high -= 1

โšกQuick SummaryAI generating...
J

Jonah Blessy

๐Ÿ“… Mar 22, 2026ยทโฑ 2 min readยทDev.to โ†—
โœˆ๏ธ Telegram๐• TweetWhatsApp
๐Ÿ“ก

Original Source

Dev.to

https://dev.to/jonah_blessy_66f109370d96/ca-08-sort-0s-1s-and-2s-5g08
Read Full โ†—

Problem Statement: here

Problem Understanding:
From a given array consisting of 0s, 1s and 2s we have to arrange them in an ascending order and print the sorted array.

Solution:

arr = [0, 1, 2, 0, 1, 2]

low = 0
mid = 0
high = len(arr) - 1

while mid <= high:
    if arr[mid] == 0:
        arr[low], arr[mid] = arr[mid], arr[low]
        low += 1
        mid += 1
    elif arr[mid] == 1:
        mid += 1
    else:
        arr[mid], arr[high] = arr[high], arr[mid]
        high -= 1

print(arr)
  • In this approach, we make use of three pointers low, mid and high.

  • Initially, low and mid point to the first element of the array and high points to the last element of the array.

  • Since we want 0s to the front of array, 1s in the middle of array and 2s to the back of array, we make sure the pointer mid is lesser than pointer high.

  • We compare each value of the mid pointer, if arr[mid]= 0, then we interchange the index of mid and low, then increment mid and low.

  • If arr[mid]= 2, we move 2 to the end of the array and decrement high.

  • Else if arr[mid]=1, we do no operation and increment mid.

  • The final array will have the sorted values.

Visual representation

Tags:#cloud#dev.to

Found this useful? Share it!

โœˆ๏ธ Telegram๐• TweetWhatsApp

Read the Full Story

Continue reading on Dev.to

Visit Dev.to โ†—

Related Stories

โ˜๏ธ
โ˜๏ธCloud & DevOps

Hiring Senior Full Stack Developer (Remote, USA)

about 2 hours ago

โ˜๏ธ
โ˜๏ธCloud & DevOps

How I Built a Multi-Tenant WhatsApp Automation Platform Using n8n and WAHA

about 2 hours ago

โ˜๏ธ
โ˜๏ธCloud & DevOps

I Built an Instant SEO Audit API โ€” Here's What I Learned About Technical SEO

about 3 hours ago

โ˜๏ธ
โ˜๏ธCloud & DevOps

SJF4J: A Structured JSON Facade for Java

about 3 hours ago

๐Ÿ“ก Source Details

Dev.to

๐Ÿ“… Mar 22, 2026

๐Ÿ• 1 day ago

โฑ 2 min read

๐Ÿ—‚ Cloud & DevOps

Read Original โ†—

Web Hosting

๐ŸŒ Hostinger โ€” 80% Off Hosting

Start your website for โ‚น69/mo. Free domain + SSL included.

Claim Deal โ†’

๐Ÿ“ฌ AiFeed24 Daily

Top 5 AI & tech stories every morning. Join 40,000+ readers.

โœฆ 40,218 subscribers ยท No spam, ever

Cloud Hosting

โ˜๏ธ Vultr โ€” $100 Free Credit

Deploy cloud servers in 25+ locations. From $2.50/mo. No contract.

Claim $100 Credit โ†’
AiFeed24

India's AI-powered tech news hub. Daily coverage of AI, startups, crypto and emerging technology.

โœˆ๏ธ๐Ÿ›’

Topics

Artificial IntelligenceStartups & VCCryptocurrencyCybersecurityCloud & DevOpsIndia Tech

Company

About AiFeed24Write For UsContact

Daily Digest

Top 5 AI stories every morning. 40,000+ readers.

No spam, ever.

ยฉ 2026 AiFeed24 Media.Affiliate Disclosure โ€” We earn commission on qualifying purchases at no extra cost to you.
PrivacyTermsCookies