DataDrivenDataDriven
LearnPracticeInterviewDiscussDailyJobs

The String Shrinker

A easy Python interview practice problem on DataDriven. Write and execute real python code with instant feedback.

Domain
Python
Difficulty
easy
Seniority
L4

Problem

A storage layer keeps text compact by collapsing repeated characters: given a string `s`, return its run-length encoding, where each run becomes the character followed by its length, and a lone character keeps just itself. If the encoded form would not be shorter than `s`, return `s` unchanged.

Summary

Compress the string. Shorter wins.

Practice This Problem

Solve this Python problem with real code execution. DataDriven runs your Python code in a real environment and checks it automatically.

Related

  • All Practice Problems
  • Mock Interview Mode
  • Python Interview Questions
  • Data Engineering Interview Prep Guide
  • Daily Challenge
  • Data Engineering Lessons