Close Menu
Luminari | Learn Docker, Kubernetes, AI, Tech & Interview PrepLuminari | Learn Docker, Kubernetes, AI, Tech & Interview Prep
  • Home
  • Technology
    • Docker
    • Kubernetes
    • AI
    • Cybersecurity
    • Blockchain
    • Linux
    • Python
    • Tech Update
    • Interview Preparation
    • Internet
  • Entertainment
    • Movies
    • TV Shows
    • Anime
    • Cricket
What's Hot

Tornado Cash dev’s attorneys say prosecutors hid exculpatory evidence

May 18, 2025

Grok says it’s ‘skeptical’ about Holocaust death toll, then blames ‘programming error’

May 18, 2025

Wes Anderson Thrills Cannes With ‘The Phoenician Scheme’ Premiere

May 18, 2025
Facebook X (Twitter) Instagram
Facebook X (Twitter) Instagram
Luminari | Learn Docker, Kubernetes, AI, Tech & Interview Prep
  • Home
  • Technology
    • Docker
    • Kubernetes
    • AI
    • Cybersecurity
    • Blockchain
    • Linux
    • Python
    • Tech Update
    • Interview Preparation
    • Internet
  • Entertainment
    • Movies
    • TV Shows
    • Anime
    • Cricket
Luminari | Learn Docker, Kubernetes, AI, Tech & Interview PrepLuminari | Learn Docker, Kubernetes, AI, Tech & Interview Prep
Home » Simple data compression algorithm
Misc

Simple data compression algorithm

HarishBy HarishJuly 14, 2024No Comments1 Min Read
Facebook Twitter Pinterest LinkedIn Reddit WhatsApp Email
Share
Facebook Twitter Pinterest Reddit WhatsApp Email
Question:

write a program for simple data compression algorithm

Example:

data = [1,2,3,4,0,0,0,3,4,6,0,0,0,21,2,3]

out = [1,2,3,4,”3×0″,4,6,”2×0″,21,2,3]

Logic:

  1. Initialize comp_count to 1 and an empty list called result.

  2. Iterate over the input list data (except for the last element).

  3. If the current element is the same as the next element, increment comp_count.

  4. If the current element is different from the next element:

    • If there were consecutive identical elements (i.e., comp_count > 1), append the count and the element to result.

    • Append the current element to result.

    • Reset comp_count to 1 for the next element.

  5. Return the compressed list in the format “count x element”.

Solution in python:

# Example 1

data = [1,2,3,4,0,0,0,3,4,6,0,0,0,21,2,3]

out = [1,2,3,4,”3×0″,4,6,”2×0″,21,2,3]

# Example 2

data = [1, 1, 2, 2, 2, 3, 4, 4, 4, 4],

output would be [‘2×1’, ‘3×2’, 3, ‘4×4’]

Preparing for interview?

  • Checkout our Interview prep page, It might help you.

Share. Facebook Twitter Pinterest LinkedIn WhatsApp Reddit Email
Previous ArticleInterview questions- SAN, FLOGI, PLOGI, Process login and zoning
Next Article Learn Docker for free : Building images
Harish
  • Website
  • X (Twitter)

Related Posts

We’ve entered an era of fintech maximalism according to Mark Goldberg

April 16, 2025

Apple says zero-day bugs exploited against ‘specific targeted individuals’ using iOS

April 16, 2025

India’s Uber-rival BluSmart appears to suspend service in wake of EV loan probe

April 16, 2025

Bluesky feed builder Graze raises $1M, rolls out ads

April 16, 2025

Kia is pitching Americans an affordable EV sedan with EV4 debut

April 16, 2025

NSO lawyer names Mexico, Saudi Arabia, and Uzbekistan as spyware customers accused of 2019 WhatsApp hacks

April 16, 2025
Add A Comment
Leave A Reply Cancel Reply

Our Picks

Tornado Cash dev’s attorneys say prosecutors hid exculpatory evidence

May 18, 2025

Grok says it’s ‘skeptical’ about Holocaust death toll, then blames ‘programming error’

May 18, 2025

Wes Anderson Thrills Cannes With ‘The Phoenician Scheme’ Premiere

May 18, 2025

Anime Expo Hosts Mobile Suit Gundam GQuuuuuuX Staff, Naohiro Ogata, Peach-Pit, More – News

May 18, 2025
Don't Miss
Blockchain

Tornado Cash dev’s attorneys say prosecutors hid exculpatory evidence

May 18, 20252 Mins Read

Attorneys for Tornado Cash developer Roman Storm filed a motion asking the court to reconsider…

‘Bitcoin Standard’ author backs funding dev to make spamming Bitcoin costly

May 18, 2025

The Public internet is a bottleneck for blockchain — DoubleZero CEO

May 17, 2025

High-speed oracles disrupting $50B finance data industry — Web3 Exec

May 17, 2025

Subscribe to Updates

Subscribe to our newsletter and never miss our latest news

Subscribe my Newsletter for New Posts & tips Let's stay updated!

About Us
About Us

Welcome to Luminari, your go-to hub for mastering modern tech and staying ahead in the digital world.

At Luminari, we’re passionate about breaking down complex technologies and delivering insights that matter. Whether you’re a developer, tech enthusiast, job seeker, or lifelong learner, our mission is to equip you with the tools and knowledge you need to thrive in today’s fast-moving tech landscape.

Our Picks

Grok says it’s ‘skeptical’ about Holocaust death toll, then blames ‘programming error’

May 18, 2025

U.S. lawmakers have concerns about Apple-Alibaba deal

May 18, 2025

Microsoft’s Satya Nadella is choosing chatbots over podcasts

May 17, 2025

Subscribe to Updates

Subscribe to our newsletter and never miss our latest news

Subscribe my Newsletter for New Posts & tips Let's stay updated!

Facebook X (Twitter) Instagram Pinterest
  • Home
  • About Us
  • Advertise With Us
  • Contact Us
  • DMCA Policy
  • Privacy Policy
  • Terms & Conditions
© 2025 luminari. Designed by luminari.

Type above and press Enter to search. Press Esc to cancel.