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

Bengaluru or Colombo to host 2025 Women’s World Cup final

June 4, 2025

FBI says Palm Springs bombing suspects used AI chat program

June 4, 2025

‘One of Them Days’ Sequel Movie in the Works With Keke Palmer, SZA

June 4, 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

Bengaluru or Colombo to host 2025 Women’s World Cup final

June 4, 2025

FBI says Palm Springs bombing suspects used AI chat program

June 4, 2025

‘One of Them Days’ Sequel Movie in the Works With Keke Palmer, SZA

June 4, 2025

Your Score: Simulcast Week of 2025-05-26

June 4, 2025
Don't Miss
Blockchain

Swift legislation turns Kyrgyzstan into Central Asia’s primary crypto hub

June 4, 20255 Mins Read

Kyrgyzstan’s growing reputation as a crypto-friendly jurisdiction stems from careful and comprehensive regulatory measures implemented…

Canada’s direction on digital asset innovation remains uncertain.

June 4, 2025

What South Korea president Lee Jae-myung means for crypto

June 4, 2025

How to use Chainabuse and Scamwatch to report a Bitcoin scammer

June 4, 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

Hugging Face says its new robotics model is so efficient it can run on a MacBook

June 4, 2025

Reddit sues Anthropic for allegedly not paying for training data

June 4, 2025

Klarna CEO says company will use humans to offer VIP customer service

June 4, 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.